Merge pull request #231 from metosin/CatchAllShouldMatchWithEmptyParameter

CatchAll matcher catch with empty parameter, fixes #230
This commit is contained in:
Tommi Reiman 2019-03-06 20:18:27 +02:00 committed by GitHub
commit d50da2bc85
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 4 deletions

View file

@ -211,7 +211,7 @@ public class Trie {
@Override
public Match match(int i, int max, char[] path) {
if (i < max) {
if (i <= max) {
return new Match(params.assoc(parameter, decode(path, i, max)), data);
}
return null;

View file

@ -240,7 +240,7 @@
(let [match (->Match params data)]
(reify Matcher
(match [_ i max path]
(if (< i max) (assoc-param match key (decode path i max true))))
(if (<= i max) (assoc-param match key (decode path i max true))))
(view [_] [key [data]])
(depth [_] 1)
(length [_]))))

View file

@ -87,6 +87,7 @@
(is (= ::boo (by-path "/abba/1/boo")))
(is (= ::baa (by-path "/abba/dabba/boo/baa")))
(is (= ::boo (by-path "/abba/dabba/boo")))
(is (= ::wild (by-path "/olipa/kerran/avaruus/vaan/")))
(is (= ::wild (by-path "/olipa/kerran/avaruus/vaan/ei/toista/kertaa")))))
(testing "bracket-params"
@ -387,5 +388,10 @@
(let [router (r/router
[["/" :root]
["/" {:name :create :method :post}]]
{:conflicts nil})]
(is (= :root (-> (r/match-by-path router "/") :data :name)))))
{:conflicts nil})
router2 (r/router
[["/*a" :root]
["/:a/b/c/d" {:name :create :method :post}]]
{:conflicts nil})]
(is (= :root (-> (r/match-by-path router "/") :data :name)))
(is (= :root (-> (r/match-by-path router2 "/") :data :name)))))