Allow space as separator, fixes #411

Fixes https://github.com/metosin/reitit/issues/411
This commit is contained in:
Kimmo Koskinen 2021-01-29 15:02:35 +02:00
parent 0ecc2fb9a7
commit 496e6b6fc7
2 changed files with 12 additions and 3 deletions

View file

@ -167,7 +167,7 @@
(instance? CatchAll path)
(assoc-in node [:catch-all path] (-node {:params params, :data data}))
(str/blank? path)
(empty? path)
(-insert node ps fp params data)
:else
@ -439,7 +439,9 @@
["/v1/topics" 54]
["/v1/orgs" 55]
["/v1/users/:user-id/bookmarks" 56]
["/v1/orgs/:org-id/topics" 57]]
["/v1/orgs/:org-id/topics" 57]
["/command1 {arg1} {arg2}" ::cmd1]
["/command2 {arg1} {arg2} {arg3}" ::cmd2]]
(insert)
(compile)
(pretty)))

View file

@ -121,4 +121,11 @@
(trie/compile)
(trie/path-matcher)) "/a")]
(is (record? (:params match)))
(is (= (trie/->Match {:a "a"} {:a 1}) (update match :params (partial into {})))))))
(is (= (trie/->Match {:a "a"} {:a 1}) (update match :params (partial into {}))))))
(testing "space as separator"
(is (= (trie/->Match {:arg1 "say" :arg2 "hello"} ::cmd1)
((-> (trie/insert nil "/command1 {arg1} {arg2}" ::cmd1)
(trie/insert "/command2 {arg1} {arg2} {arg3}" ::cmd2)
(trie/compile)
(trie/path-matcher)) "/command1 say hello")))))