Skip to content

Commit

Permalink
reject empty route parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
ibraheemdev committed Oct 10, 2024
1 parent db7cf5a commit 7165925
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,11 @@ impl<T> Node<T> {
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.
Expand Down
13 changes: 13 additions & 0 deletions tests/match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,19 @@ fn escaped() {
.run()
}

#[test]
fn empty_param() {
MatchTest {
routes: vec!["/y/{foo}", "/x/{foo}/bar", "/foo/bar/{*xx}"],
matches: vec![
("/y/", "", Err(())),
("/x//bar", "", Err(())),
("/foo/bar/", "", Err(())),
],
}
.run();
}

#[test]
fn basic() {
MatchTest {
Expand Down

0 comments on commit 7165925

Please sign in to comment.