Merge pull request #466 from metosin/feature/space-as-separator

Allow space as separator, fixes #411
This commit is contained in:
Miikka Koskinen 2021-01-29 15:08:35 +02:00 committed by GitHub
commit eb10af92c4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 3 deletions

View file

@ -167,7 +167,7 @@
(instance? CatchAll path) (instance? CatchAll path)
(assoc-in node [:catch-all path] (-node {:params params, :data data})) (assoc-in node [:catch-all path] (-node {:params params, :data data}))
(str/blank? path) (empty? path)
(-insert node ps fp params data) (-insert node ps fp params data)
:else :else
@ -439,7 +439,9 @@
["/v1/topics" 54] ["/v1/topics" 54]
["/v1/orgs" 55] ["/v1/orgs" 55]
["/v1/users/:user-id/bookmarks" 56] ["/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) (insert)
(compile) (compile)
(pretty))) (pretty)))

View file

@ -121,4 +121,11 @@
(trie/compile) (trie/compile)
(trie/path-matcher)) "/a")] (trie/path-matcher)) "/a")]
(is (record? (:params match))) (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")))))