matchit
matchit copied to clipboard
Panic when inserting routes without leading slash
Description
-
Pass: Inserting
"{foo}/"then"foo/". -
Panic: Inserting
"foo/"then"{foo}/".
Reproduction
#[test]
fn local_test() {
InsertTest(vec![("{foo}/", Ok(())), ("foo/", Ok(()))]).run(); // ok
InsertTest(vec![("foo/", Ok(())), ("{foo}/", Ok(()))]).run() // panic
}
Investigation
// tree.rs
if common_remaining[common_prefix - 1] != b'/'
&& node.suffix_wild_child_in_segment()
{
return Err(InsertError::conflict(&route, remaining, node));
}
common_prefix is 0 when routes do not have a leading slash,
Question
With a leading slash, this will not be a problem. But i found some routes in test do not have the leading slash. Is matchit intended to support routes without the leading slash?
Thanks for the report, this looks like a regression in the latest release. We should support routes without a leading slash.
It looks like this can be fixed with a simple zero check.