mirror of
https://github.com/metosin/reitit.git
synced 2026-02-15 07:45:17 +00:00
Undo ensure-slash
This commit is contained in:
parent
33582b4c1c
commit
46254975d9
2 changed files with 11 additions and 25 deletions
|
|
@ -30,12 +30,6 @@
|
||||||
nil
|
nil
|
||||||
(expand [_ _]))
|
(expand [_ _]))
|
||||||
|
|
||||||
(defn ensure-slash
|
|
||||||
[^String string]
|
|
||||||
(if (.endsWith string "/")
|
|
||||||
(str/replace string #"/+$" "")
|
|
||||||
string))
|
|
||||||
|
|
||||||
(defn walk [raw-routes {:keys [path data routes expand]
|
(defn walk [raw-routes {:keys [path data routes expand]
|
||||||
:or {data [], routes [], expand expand}
|
:or {data [], routes [], expand expand}
|
||||||
:as opts}]
|
:as opts}]
|
||||||
|
|
@ -55,9 +49,7 @@
|
||||||
[maybe-arg (rest args)])
|
[maybe-arg (rest args)])
|
||||||
macc (into macc (expand data opts))
|
macc (into macc (expand data opts))
|
||||||
child-routes (walk-many (str pacc path) macc (keep identity childs))]
|
child-routes (walk-many (str pacc path) macc (keep identity childs))]
|
||||||
(if (seq childs)
|
(if (seq childs) (seq child-routes) [[(str pacc path) macc]])))))]
|
||||||
(seq child-routes)
|
|
||||||
[[(str pacc (ensure-slash path)) macc]])))))]
|
|
||||||
(walk-one path (mapv identity data) raw-routes)))
|
(walk-one path (mapv identity data) raw-routes)))
|
||||||
|
|
||||||
(defn map-data [f routes]
|
(defn map-data [f routes]
|
||||||
|
|
@ -208,13 +200,8 @@
|
||||||
(match-by-path [_ path]
|
(match-by-path [_ path]
|
||||||
(reduce
|
(reduce
|
||||||
(fn [_ ^Route route]
|
(fn [_ ^Route route]
|
||||||
(let [slashed-path (ensure-slash path)]
|
(if-let [path-params ((:matcher route) path)]
|
||||||
(if-let [path-params ((:matcher route) slashed-path)]
|
(reduced (->Match (:path route) (:data route) (:result route) (impl/url-decode-coll path-params) path))))
|
||||||
(reduced (->Match (:path route)
|
|
||||||
(:data route)
|
|
||||||
(:result route)
|
|
||||||
(impl/url-decode-coll path-params)
|
|
||||||
slashed-path)))))
|
|
||||||
nil pl))
|
nil pl))
|
||||||
(match-by-name [_ name]
|
(match-by-name [_ name]
|
||||||
(if-let [match (impl/fast-get lookup name)]
|
(if-let [match (impl/fast-get lookup name)]
|
||||||
|
|
@ -260,7 +247,7 @@
|
||||||
(route-names [_]
|
(route-names [_]
|
||||||
names)
|
names)
|
||||||
(match-by-path [_ path]
|
(match-by-path [_ path]
|
||||||
(impl/fast-get data (ensure-slash path)))
|
(impl/fast-get data path))
|
||||||
(match-by-name [_ name]
|
(match-by-name [_ name]
|
||||||
(if-let [match (impl/fast-get lookup name)]
|
(if-let [match (impl/fast-get lookup name)]
|
||||||
(match nil)))
|
(match nil)))
|
||||||
|
|
@ -301,11 +288,10 @@
|
||||||
(route-names [_]
|
(route-names [_]
|
||||||
names)
|
names)
|
||||||
(match-by-path [_ path]
|
(match-by-path [_ path]
|
||||||
(let [slashed-path (ensure-slash path)]
|
(if-let [match (segment/lookup pl path)]
|
||||||
(if-let [match (segment/lookup pl slashed-path)]
|
(-> (:data match)
|
||||||
(-> (:data match)
|
(assoc :path-params (impl/url-decode-coll (:path-params match)))
|
||||||
(assoc :path-params (impl/url-decode-coll (:path-params match)))
|
(assoc :path path))))
|
||||||
(assoc :path slashed-path)))))
|
|
||||||
(match-by-name [_ name]
|
(match-by-name [_ name]
|
||||||
(if-let [match (impl/fast-get lookup name)]
|
(if-let [match (impl/fast-get lookup name)]
|
||||||
(match nil)))
|
(match nil)))
|
||||||
|
|
@ -342,7 +328,7 @@
|
||||||
(route-names [_]
|
(route-names [_]
|
||||||
names)
|
names)
|
||||||
(match-by-path [_ path]
|
(match-by-path [_ path]
|
||||||
(if (#?(:clj .equals :cljs =) p (ensure-slash path))
|
(if (#?(:clj .equals :cljs =) p path)
|
||||||
match))
|
match))
|
||||||
(match-by-name [_ name]
|
(match-by-name [_ name]
|
||||||
(if (= n name)
|
(if (= n name)
|
||||||
|
|
|
||||||
|
|
@ -230,8 +230,8 @@
|
||||||
true [["/a/1/2"]
|
true [["/a/1/2"]
|
||||||
["/*b"]]
|
["/*b"]]
|
||||||
|
|
||||||
true [["/a"]
|
false [["/a"]
|
||||||
["/a/"]]
|
["/a/"]]
|
||||||
|
|
||||||
false [["/a"]
|
false [["/a"]
|
||||||
["/a/1"]]
|
["/a/1"]]
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue