Skip to content

Commit

Permalink
fix full splat routes
Browse files Browse the repository at this point in the history
Signed-off-by: Rudi Grinberg <[email protected]>
  • Loading branch information
rgrinberg committed Dec 28, 2020
1 parent bda4a02 commit 27a6131
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
12 changes: 11 additions & 1 deletion opium/src/router.ml
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,17 @@ let match_route t route =
| Accept (a, r) -> [ a, r ]
| Node t ->
(match route with
| Full_splat -> assert false
| Full_splat ->
let here =
match t.data with
| None -> []
| Some (a, r) -> [ a, r ]
in
let by_param = by_param t.param route in
let by_literal =
Smap.fold (fun _ node acc -> loop node route :: acc) t.literal [] |> List.concat
in
List.concat [ here; by_param; by_literal ]
| Nil ->
(match t.data with
| None -> []
Expand Down
18 changes: 4 additions & 14 deletions opium/test/opium_router_tests.ml
Original file line number Diff line number Diff line change
Expand Up @@ -192,18 +192,8 @@ let%expect_test "full splat" =
test "/test";
test "/";
test "/user/123/foo/bar";
[%expect.unreachable]
[@@expect.uncaught_exn
{|
(* CR expect_test_collector: This test expectation appears to contain a backtrace.
This is strongly discouraged as backtraces are fragile.
Please change this test to not include a backtrace. *)
"Assert_failure opium/src/router.ml:200:22"
Raised at Opium__Router.match_route.loop in file "opium/src/router.ml", line 200, characters 22-34
Called from Opium__Router.match_route in file "opium/src/router.ml", line 224, characters 8-20
Called from Opium__Router.add in file "opium/src/router.ml", line 264, characters 8-27
Called from Stdlib__list.fold_left in file "list.ml", line 121, characters 24-34
Called from Opium_tests__Opium_router_tests.(fun) in file "opium/test/opium_router_tests.ml", line 190, characters 15-35
Called from Expect_test_collector.Make.Instance.exec in file "collector/expect_test_collector.ml", line 244, characters 12-19 |}]
[%expect{|
matched with params: ((named ()) (unnamed ()))
matched with params: ((named ()) (unnamed ()))
matched with params: ((named ()) (unnamed ())) |}]
;;

0 comments on commit 27a6131

Please sign in to comment.