From aa11313e99c84fa439615529824f0a718bf6c678 Mon Sep 17 00:00:00 2001 From: Niclas Axelsson Date: Sun, 6 Mar 2022 21:54:53 +0100 Subject: [PATCH 1/2] Add test for path with dash --- src/routing_tree.erl | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/routing_tree.erl b/src/routing_tree.erl index 59dd75e..232d015 100644 --- a/src/routing_tree.erl +++ b/src/routing_tree.erl @@ -488,6 +488,12 @@ wildcard_binary_lookup_test() -> Expected = {ok, #{}, "ONE", [<<"is">>, <<"amazing">>]}, ?assertEqual(Expected, C). +dash_in_path_test() -> + A = new(#{convert_to_binary => true}), + B = insert('_', "/my-test-route", "GET", "ONE", A), + C = lookup(<<"My host">>, <<"/my-test-route">>, "GET", B), + Expected = {ok, #{}, "ONE"}, + ?assertEqual(Expected, C). From a64c3b2b6f98137877bfc116bf2bf9375eaf5a7c Mon Sep 17 00:00:00 2001 From: Niclas Axelsson Date: Sun, 6 Mar 2022 22:14:43 +0100 Subject: [PATCH 2/2] Fix the rules so it does not contain uneven shift/reduce --- src/routing_tree_parser.yrl | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/src/routing_tree_parser.yrl b/src/routing_tree_parser.yrl index a2149a9..543153a 100644 --- a/src/routing_tree_parser.yrl +++ b/src/routing_tree_parser.yrl @@ -1,8 +1,8 @@ -Nonterminals url_path path_segment query basic_element. +Nonterminals path_segment query basic_element. Terminals 'divider' 'binding' 'wildcard' 'segment' 'query_start' 'ampersand' 'equals'. -Rootsymbol url_path. +Rootsymbol path_segment. basic_element -> @@ -26,11 +26,4 @@ path_segment -> path_segment -> 'divider' basic_element path_segment: ['$2'|'$3']. -%% Remove trailing slash -url_path -> - path_segment 'divider': '$1'. -url_path -> - path_segment: '$1'. - - Erlang code.