diff --git a/modules/reitit-core/src/reitit/core.cljc b/modules/reitit-core/src/reitit/core.cljc index 58893e77..d56f3bbb 100644 --- a/modules/reitit-core/src/reitit/core.cljc +++ b/modules/reitit-core/src/reitit/core.cljc @@ -46,7 +46,7 @@ (options [this]) (route-names [this]) (match-by-path [this path]) - (match-by-name [this name] [this name path-params])) + (match-by-name [this name] [this name path-params] [this name path-params opts])) (defn router? [x] (satisfies? Router x)) @@ -122,9 +122,11 @@ (match-by-name [_ name] (if-let [match (impl/fast-get lookup name)] (match nil))) - (match-by-name [_ name path-params] + (match-by-name [r name path-params] + (match-by-name r name path-params nil)) + (match-by-name [_ name path-params opts] (if-let [match (impl/fast-get lookup name)] - (match (impl/path-params path-params)))))))) + (match (impl/path-params path-params opts)))))))) (defn lookup-router "Creates a lookup-router from resolved routes and optional @@ -161,9 +163,11 @@ (match-by-name [_ name] (if-let [match (impl/fast-get lookup name)] (match nil))) - (match-by-name [_ name path-params] + (match-by-name [r name path-params] + (match-by-name r name path-params nil)) + (match-by-name [_ name path-params opts] (if-let [match (impl/fast-get lookup name)] - (match (impl/path-params path-params)))))))) + (match (impl/path-params path-params opts)))))))) (defn trie-router "Creates a special prefix-tree router from resolved routes and optional @@ -208,9 +212,11 @@ (match-by-name [_ name] (if-let [match (impl/fast-get lookup name)] (match nil))) - (match-by-name [_ name path-params] + (match-by-name [r name path-params] + (match-by-name r name path-params nil)) + (match-by-name [_ name path-params opts] (if-let [match (impl/fast-get lookup name)] - (match (impl/path-params path-params)))))))) + (match (impl/path-params path-params opts)))))))) (defn single-static-path-router "Creates a fast router of 1 static route(s) and optional @@ -238,8 +244,10 @@ (if (#?(:clj .equals :cljs =) p path) match)) (match-by-name [_ name] (if (= n name) match)) - (match-by-name [_ name path-params] - (if (= n name) (impl/fast-assoc match :path-params (impl/path-params path-params)))))))) + (match-by-name [r name path-params] + (match-by-name r name path-params nil)) + (match-by-name [_ name path-params opts] + (if (= n name) (impl/fast-assoc match :path-params (impl/path-params path-params opts)))))))) (defn mixed-router "Creates two routers: [[lookup-router]] or [[single-static-path-router]] for @@ -268,9 +276,11 @@ (match-by-name [_ name] (or (match-by-name static-router name) (match-by-name wildcard-router name))) - (match-by-name [_ name path-params] - (or (match-by-name static-router name path-params) - (match-by-name wildcard-router name path-params))))))) + (match-by-name [r name path-params] + (match-by-name r name path-params nil)) + (match-by-name [_ name path-params opts] + (or (match-by-name static-router name path-params opts) + (match-by-name wildcard-router name path-params opts))))))) (defn quarantine-router "Creates two routers: [[mixed-router]] for non-conflicting routes @@ -299,9 +309,11 @@ (match-by-name [_ name] (or (match-by-name mixed-router name) (match-by-name linear-router name))) - (match-by-name [_ name path-params] - (or (match-by-name mixed-router name path-params) - (match-by-name linear-router name path-params))))))) + (match-by-name [r name path-params] + (match-by-name r name path-params nil)) + (match-by-name [_ name path-params opts] + (or (match-by-name mixed-router name path-params opts) + (match-by-name linear-router name path-params opts))))))) ;; ;; Creating Routers diff --git a/modules/reitit-core/src/reitit/impl.cljc b/modules/reitit-core/src/reitit/impl.cljc index 30c39ec2..5e40e01e 100644 --- a/modules/reitit-core/src/reitit/impl.cljc +++ b/modules/reitit-core/src/reitit/impl.cljc @@ -297,8 +297,11 @@ (defn path-params "Convert parameters' values into URL-encoded strings, suitable for URL paths" - [params] - (maybe-map-values #(url-encode (into-string %)) params)) + ([params] (path-params params nil)) + ([params {:keys [url-encode?] :or {url-encode? true}}] + (if url-encode? + (maybe-map-values #(url-encode (into-string %)) params) + (maybe-map-values #(into-string %) params)))) (defn- query-parameter [k v] (str (form-encode (into-string k)) diff --git a/test/cljc/reitit/core_test.cljc b/test/cljc/reitit/core_test.cljc index 0be783f0..8f8ee759 100644 --- a/test/cljc/reitit/core_test.cljc +++ b/test/cljc/reitit/core_test.cljc @@ -33,6 +33,12 @@ :path "/api/ipa/large" :path-params {:size "large"}}) (r/match-by-name router ::beer {:size "large"}))) + (is (= (r/map->Match + {:template "/api/ipa/:size" + :data {:name ::beer} + :path "/api/ipa/:large" + :path-params {:size ":large"}}) + (r/match-by-name router ::beer {:size ":large"} {:url-encode? false}))) (is (= (r/map->Match {:template "/api/ipa/:size" :data {:name ::beer} diff --git a/test/cljc/reitit/impl_test.cljc b/test/cljc/reitit/impl_test.cljc index c4ae1a39..41da5614 100644 --- a/test/cljc/reitit/impl_test.cljc +++ b/test/cljc/reitit/impl_test.cljc @@ -41,7 +41,33 @@ :u #uuid "c2541900-17a7-4353-9024-db8ac258ba4e" :k :kikka :qk ::kikka - :nil nil})))) + :nil nil}))) + (is (= {:n "1" + :n1 "-1" + :n2 "1" + :n3 "1" + :n4 "1" + :n5 "1" + :d "2.2" + :b "true" + :s "kikka" + :u "c2541900-17a7-4353-9024-db8ac258ba4e" + :k "kikka" + :qk "reitit.impl-test/kikka" + :nil nil} + (impl/path-params {:n 1 + :n1 -1 + :n2 (long 1) + :n3 (int 1) + :n4 (short 1) + :n5 (byte 1) + :d 2.2 + :b true + :s "kikka" + :u #uuid "c2541900-17a7-4353-9024-db8ac258ba4e" + :k :kikka + :qk ::kikka + :nil nil} {:url-encode? false})))) (deftest query-params-test (are [x y]