fix: do not match static segment with last character missing before slash (closes #3817) (#3823)

This commit is contained in:
Greg Johnston
2025-04-05 21:58:50 -04:00
committed by GitHub
parent b8810ba42f
commit 9128545388

View File

@@ -85,7 +85,12 @@ impl<T: AsPath> PossibleRouteMatch for StaticSegment<T> {
for char in test {
let n = this.next();
// when we get a closing /, stop matching
if char == '/' || n.is_none() {
if char == '/' {
if n.is_some() {
return None;
}
break;
} else if n.is_none() {
break;
}
// if the next character in the path matches the
@@ -269,4 +274,15 @@ mod tests {
let params = matched.params();
assert!(params.is_empty());
}
#[test]
fn only_match_full_static_paths() {
let def = (StaticSegment("tests"), StaticSegment("abc"));
assert!(def.test("/tes/abc").is_none());
assert!(def.test("/test/abc").is_none());
assert!(def.test("/tes/abc/").is_none());
assert!(def.test("/test/abc/").is_none());
assert!(def.test("/tests/ab").is_none());
assert!(def.test("/tests/ab/").is_none());
}
}