mirror of
https://github.com/metosin/reitit.git
synced 2025-12-17 00:11:11 +00:00
Merge pull request #231 from metosin/CatchAllShouldMatchWithEmptyParameter
CatchAll matcher catch with empty parameter, fixes #230
This commit is contained in:
commit
d50da2bc85
3 changed files with 10 additions and 4 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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 [_]))))
|
||||
|
|
|
|||
|
|
@ -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)))))
|
||||
|
|
|
|||
Loading…
Reference in a new issue