File tree Expand file tree Collapse file tree 2 files changed +14
-8
lines changed
Expand file tree Collapse file tree 2 files changed +14
-8
lines changed Original file line number Diff line number Diff line change @@ -119,7 +119,7 @@ module Params = struct
119119 | Param (Some name , route ), p :: captured ->
120120 let acc = { acc with named = (name, p) :: acc.named } in
121121 loop acc route captured
122- | Full_splat , _ :: _ -> assert false
122+ | Full_splat , rest -> { acc with unnamed = List. rev_append rest acc.unnamed }
123123 | Param (_ , _ ), [] -> assert false
124124 | Nil , _ :: _ -> assert false
125125 in
@@ -167,7 +167,7 @@ let match_url t url =
167167 in
168168 let rec loop t captured tokens =
169169 match t with
170- | Accept (a , route ) -> accept a route captured
170+ | Accept (a , route ) -> accept a route ( List. rev_append tokens captured)
171171 | Node t ->
172172 (match tokens with
173173 | [ " " ] | [] ->
@@ -205,6 +205,7 @@ let match_route t route =
205205 in
206206 let by_param = by_param t.param route in
207207 let by_literal =
208+ (* TODO remove duplication with [Param] case *)
208209 Smap. fold (fun _ node acc -> loop node route :: acc) t.literal [] |> List. concat
209210 in
210211 List. concat [ here; by_param; by_literal ]
Original file line number Diff line number Diff line change @@ -155,9 +155,9 @@ let%expect_test "full splat node matches" =
155155 test "/foo/";
156156 [%expect
157157 {|
158- matched with params: ((named ()) (unnamed ()))
159- matched with params: ((named ()) (unnamed ()))
160- matched with params: ((named ()) (unnamed ())) |}]
158+ matched with params: ((named ()) (unnamed (bar )))
159+ matched with params: ((named ()) (unnamed (bar foo )))
160+ matched with params: ((named ()) (unnamed ("" ))) |}]
161161;;
162162
163163let%expect_test "full splat + collision checking" =
@@ -190,10 +190,15 @@ let%expect_test "full splat" =
190190 let router = of_routes' [ "/**" ] in
191191 let test = test_match_url router in
192192 test "/test";
193+ test "/test/";
193194 test "/";
195+ test "";
194196 test "/user/123/foo/bar";
195- [%expect{|
196- matched with params: ((named ()) (unnamed ()))
197+ [%expect
198+ {|
199+ matched with params: ((named ()) (unnamed (test)))
200+ matched with params: ((named ()) (unnamed (test "")))
201+ matched with params: ((named ()) (unnamed ("")))
197202 matched with params: ((named ()) (unnamed ()))
198- matched with params: ((named ()) (unnamed ())) |}]
203+ matched with params: ((named ()) (unnamed (user 123 foo bar ))) |}]
199204;;
You can’t perform that action at this time.
0 commit comments