File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -393,8 +393,10 @@ impl<T> Node<T> {
393393 }
394394
395395 // Similarly, if we are inserting a longer prefix, and there is a route that leads to this
396- // parameter that includes a suffix, we have a prefix-suffix conflicts.
397- if common_remaining[ common_prefix - 1 ] != b'/'
396+ // parameter that includes a suffix, we have a prefix-suffix conflict.
397+ if common_prefix
398+ . checked_sub ( 1 )
399+ . is_some_and ( |i| common_remaining[ i] != b'/' )
398400 && node. suffix_wild_child_in_segment ( )
399401 {
400402 return Err ( InsertError :: conflict ( & route, remaining, node) ) ;
Original file line number Diff line number Diff line change @@ -16,10 +16,18 @@ fn conflict(with: &'static str) -> InsertError {
1616 InsertError :: Conflict { with : with. into ( ) }
1717}
1818
19- // https://github.com/ibraheemdev/matchit/issues/84
19+ // Regression test for https://github.com/ibraheemdev/matchit/issues/84.
2020#[ test]
21- fn root_prefix_issue ( ) {
22- InsertTest ( vec ! [ ( "{foo}" , Ok ( ( ) ) ) , ( "{foo}suffix" , Ok ( ( ) ) ) ] ) . run ( )
21+ fn missing_leading_slash_suffix ( ) {
22+ InsertTest ( vec ! [ ( "/{foo}" , Ok ( ( ) ) ) , ( "/{foo}suffix" , Ok ( ( ) ) ) ] ) . run ( ) ;
23+ InsertTest ( vec ! [ ( "{foo}" , Ok ( ( ) ) ) , ( "{foo}suffix" , Ok ( ( ) ) ) ] ) . run ( ) ;
24+ }
25+
26+ // Regression test for https://github.com/ibraheemdev/matchit/issues/82.
27+ #[ test]
28+ fn missing_leading_slash_conflict ( ) {
29+ InsertTest ( vec ! [ ( "{foo}/" , Ok ( ( ) ) ) , ( "foo/" , Ok ( ( ) ) ) ] ) . run ( ) ;
30+ InsertTest ( vec ! [ ( "foo/" , Ok ( ( ) ) ) , ( "{foo}/" , Ok ( ( ) ) ) ] ) . run ( ) ;
2331}
2432
2533#[ test]
You can’t perform that action at this time.
0 commit comments