mirror of
https://github.com/metosin/reitit.git
synced 2025-12-16 16:01:11 +00:00
Segment-router doesn't allow empty path-parameters
This commit is contained in:
parent
147034d914
commit
492d5e2f2b
3 changed files with 21 additions and 2 deletions
|
|
@ -1,3 +1,9 @@
|
|||
## UNRELEASED
|
||||
|
||||
## `reitit-core`
|
||||
|
||||
* `segment-router` doesn't accept empty segments as path-parameters, fixes [#181](https://github.com/metosin/reitit/issues/181).
|
||||
|
||||
## 0.2.9 (2018-11-21)
|
||||
|
||||
## `reitit-spec`
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@
|
|||
(if (nil? p)
|
||||
(when match (assoc match :path-params path-params))
|
||||
(or (-lookup (impl/fast-get children' p) ps path-params)
|
||||
(if wilds? (some #(-lookup (impl/fast-get children' %) ps (assoc path-params % p)) wilds))
|
||||
(if (and wilds? (not (str/blank? p))) (some #(-lookup (impl/fast-get children' %) ps (assoc path-params % p)) wilds))
|
||||
(if catch-all (-catch-all children' catch-all path-params p ps)))))))))
|
||||
|
||||
(defn insert [root path data]
|
||||
|
|
|
|||
|
|
@ -79,7 +79,20 @@
|
|||
(is (= ::jabba2 (matches "/abba/2")))
|
||||
(is (= ::doo (matches "/abba/1/doo")))
|
||||
(is (= ::boo (matches "/abba/1/boo")))
|
||||
(is (= ::wild (matches "/olipa/kerran/avaruus/vaan/ei/toista/kertaa"))))))
|
||||
(is (= ::wild (matches "/olipa/kerran/avaruus/vaan/ei/toista/kertaa")))))
|
||||
|
||||
(testing "empty path segments"
|
||||
(let [router (r/router
|
||||
[["/items" ::list]
|
||||
["/items/:id" ::item]
|
||||
["/items/:id/:side" ::deep]]
|
||||
{:router r})
|
||||
matches #(-> router (r/match-by-path %) :data :name)]
|
||||
(is (= ::list (matches "/items")))
|
||||
(is (= nil (matches "/items/")))
|
||||
(is (= ::item (matches "/items/1")))
|
||||
(is (= ::deep (matches "/items/1/2")))
|
||||
(is (= nil (matches "/items//2"))))))
|
||||
|
||||
r/linear-router :linear-router
|
||||
r/segment-router :segment-router
|
||||
|
|
|
|||
Loading…
Reference in a new issue