diff --git a/src/tree.rs b/src/tree.rs index 69a0149..3965ac8 100644 --- a/src/tree.rs +++ b/src/tree.rs @@ -562,6 +562,11 @@ impl Node { NodeType::Param => { // Check for more path segments. let i = match path.iter().position(|&c| c == b'/') { + // Double `//` implying an empty parameter, no match. + Some(0) => { + try_backtrack!(); + return Err(MatchError::NotFound); + } // Found another segment. Some(i) => i, // This is the last path segment. diff --git a/tests/match.rs b/tests/match.rs index 90130fb..acb6123 100644 --- a/tests/match.rs +++ b/tests/match.rs @@ -578,6 +578,19 @@ fn escaped() { .run() } +#[test] +fn empty_param() { + MatchTest { + routes: vec!["/y/{foo}", "/x/{foo}/z", "/z/{*xx}"], + matches: vec![ + ("/y/", "", Err(())), + ("/x//z", "", Err(())), + ("/z/", "", Err(())), + ], + } + .run(); +} + #[test] fn basic() { MatchTest {