diff --git a/modules/reitit-core/src/reitit/core.cljc b/modules/reitit-core/src/reitit/core.cljc index c6776db4..0b32fd73 100644 --- a/modules/reitit-core/src/reitit/core.cljc +++ b/modules/reitit-core/src/reitit/core.cljc @@ -103,16 +103,11 @@ ^{:type ::router} (reify Router - (router-name [_] - :linear-router) - (routes [_] - routes) - (compiled-routes [_] - compiled-routes) - (options [_] - opts) - (route-names [_] - names) + (router-name [_] :linear-router) + (routes [_] routes) + (compiled-routes [_] compiled-routes) + (options [_] opts) + (route-names [_] names) (match-by-path [_ path] (if-let [match (match-by-path path)] (-> (:data match) @@ -150,16 +145,11 @@ routes (impl/uncompile-routes compiled-routes)] ^{:type ::router} (reify Router - (router-name [_] - :lookup-router) - (routes [_] - routes) - (compiled-routes [_] - compiled-routes) - (options [_] - opts) - (route-names [_] - names) + (router-name [_] :lookup-router) + (routes [_] routes) + (compiled-routes [_] compiled-routes) + (options [_] opts) + (route-names [_] names) (match-by-path [_ path] (impl/fast-get data path)) (match-by-name [_ name] @@ -193,24 +183,19 @@ [nil {}] compiled-routes) matcher (trie/compile pl compiler) - match-by-path (trie/path-matcher matcher compiler) + match-by-path (if matcher (trie/path-matcher matcher compiler)) lookup (impl/fast-map nl) routes (impl/uncompile-routes compiled-routes)] ^{:type ::router} (reify Router - (router-name [_] - :trie-router) - (routes [_] - routes) - (compiled-routes [_] - compiled-routes) - (options [_] - opts) - (route-names [_] - names) + (router-name [_] :trie-router) + (routes [_] routes) + (compiled-routes [_] compiled-routes) + (options [_] opts) + (route-names [_] names) (match-by-path [_ path] - (if-let [match (match-by-path path)] + (if-let [match (and match-by-path (match-by-path path))] (-> (:data match) (assoc :path-params (:params match)) (assoc :path path)))) @@ -238,25 +223,17 @@ routes (impl/uncompile-routes compiled-routes)] ^{:type ::router} (reify Router - (router-name [_] - :single-static-path-router) - (routes [_] - routes) - (compiled-routes [_] - compiled-routes) - (options [_] - opts) - (route-names [_] - names) + (router-name [_] :single-static-path-router) + (routes [_] routes) + (compiled-routes [_] compiled-routes) + (options [_] opts) + (route-names [_] names) (match-by-path [_ path] - (if (#?(:clj .equals :cljs =) p path) - match)) + (if (#?(:clj .equals :cljs =) p path) match)) (match-by-name [_ name] - (if (= n name) - match)) + (if (= n name) match)) (match-by-name [_ name path-params] - (if (= n name) - (impl/fast-assoc match :path-params (impl/path-params path-params)))))))) + (if (= n name) (impl/fast-assoc match :path-params (impl/path-params path-params)))))))) (defn mixed-router "Creates two routers: [[lookup-router]] or [[single-static-path-router]] for @@ -274,16 +251,11 @@ routes (impl/uncompile-routes compiled-routes)] ^{:type ::router} (reify Router - (router-name [_] - :mixed-router) - (routes [_] - routes) - (compiled-routes [_] - compiled-routes) - (options [_] - opts) - (route-names [_] - names) + (router-name [_] :mixed-router) + (routes [_] routes) + (compiled-routes [_] compiled-routes) + (options [_] opts) + (route-names [_] names) (match-by-path [_ path] (or (match-by-path static-router path) (match-by-path wildcard-router path))) @@ -310,16 +282,11 @@ routes (impl/uncompile-routes compiled-routes)] ^{:type ::router} (reify Router - (router-name [_] - :quarantine-router) - (routes [_] - routes) - (compiled-routes [_] - compiled-routes) - (options [_] - opts) - (route-names [_] - names) + (router-name [_] :quarantine-router) + (routes [_] routes) + (compiled-routes [_] compiled-routes) + (options [_] opts) + (route-names [_] names) (match-by-path [_ path] (or (match-by-path mixed-router path) (match-by-path linear-router path))) diff --git a/modules/reitit-core/src/reitit/trie.cljc b/modules/reitit-core/src/reitit/trie.cljc index cda97066..22c6356b 100644 --- a/modules/reitit-core/src/reitit/trie.cljc +++ b/modules/reitit-core/src/reitit/trie.cljc @@ -364,8 +364,7 @@ (into (for [[p c] catch-all] (catch-all-matcher compiler (:value p) params (:data c)))))] (cond (> (count matchers) 1) (linear-matcher compiler matchers false) - (= (count matchers) 1) (first matchers) - :else (data-matcher compiler {} nil))))) + (= (count matchers) 1) (first matchers))))) (defn pretty "Returns a simplified EDN structure of a compiled trie for printing purposes." diff --git a/test/cljc/reitit/core_test.cljc b/test/cljc/reitit/core_test.cljc index 1780982c..fc112239 100644 --- a/test/cljc/reitit/core_test.cljc +++ b/test/cljc/reitit/core_test.cljc @@ -431,3 +431,7 @@ {:conflicts nil})] (is (= :root (-> (r/match-by-path router "/") :data :name))) (is (= :root (-> (r/match-by-path router2 "/") :data :name))))) + +(deftest routing-bug-test-538 + (let [router (r/router [["/:a"] ["/:b"]] {:conflicts nil})] + (is (nil? (r/match-by-path router "")))))