mirror of
https://github.com/metosin/reitit.git
synced 2025-12-31 13:48:25 +00:00
Naive encoding of supplied routes
This commit is contained in:
parent
75f5e198e4
commit
d8ca699443
2 changed files with 18 additions and 1 deletions
|
|
@ -112,6 +112,17 @@
|
|||
(defn find-names [routes _]
|
||||
(into [] (keep #(-> % second :name)) routes))
|
||||
|
||||
(defn- encode-route
|
||||
"URL-encode all non-parameter segments"
|
||||
[[p m]]
|
||||
(let [segments (str/split p #"/")
|
||||
encoded-segments (map #(if (impl/wild-or-catch-all-param? %) % (impl/url-encode %)) segments)
|
||||
encoded-path (str/join "/" encoded-segments)]
|
||||
[encoded-path m]))
|
||||
|
||||
(defn- encode-routes [routes]
|
||||
(map encode-route routes))
|
||||
|
||||
(defn- compile-route [[p m :as route] {:keys [compile] :as opts}]
|
||||
[p m (if compile (compile route opts))])
|
||||
|
||||
|
|
@ -421,7 +432,8 @@
|
|||
routes (resolve-routes raw-routes opts)
|
||||
path-conflicting (path-conflicting-routes routes)
|
||||
name-conflicting (name-conflicting-routes routes)
|
||||
compiled-routes (compile-routes routes opts)
|
||||
encoded-routes (encode-routes routes)
|
||||
compiled-routes (compile-routes encoded-routes opts)
|
||||
wilds? (boolean (some impl/wild-route? compiled-routes))
|
||||
all-wilds? (every? impl/wild-route? compiled-routes)
|
||||
router (cond
|
||||
|
|
|
|||
|
|
@ -219,6 +219,11 @@
|
|||
[coll]
|
||||
(map-kv url-decode coll))
|
||||
|
||||
(defn url-encode-coll
|
||||
"URL-encodes maps and vectors"
|
||||
[coll]
|
||||
(map-kv url-encode coll))
|
||||
|
||||
(defprotocol IntoString
|
||||
(into-string [_]))
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue