matchit icon indicating copy to clipboard operation
matchit copied to clipboard

Panic when inserting routes without leading slash

Open ck961018 opened this issue 1 month ago • 2 comments

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?

ck961018 avatar Nov 29 '25 11:11 ck961018

Thanks for the report, this looks like a regression in the latest release. We should support routes without a leading slash.

ibraheemdev avatar Dec 02 '25 05:12 ibraheemdev

It looks like this can be fixed with a simple zero check.

ck961018 avatar Dec 06 '25 05:12 ck961018