diff --git a/modules/reitit-core/src/reitit/core.cljc b/modules/reitit-core/src/reitit/core.cljc index 70a5680a..4ada0c6a 100644 --- a/modules/reitit-core/src/reitit/core.cljc +++ b/modules/reitit-core/src/reitit/core.cljc @@ -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 diff --git a/modules/reitit-core/src/reitit/impl.cljc b/modules/reitit-core/src/reitit/impl.cljc index 6f954807..cacd6175 100644 --- a/modules/reitit-core/src/reitit/impl.cljc +++ b/modules/reitit-core/src/reitit/impl.cljc @@ -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 [_]))