diff --git a/src/tree.rs b/src/tree.rs index a7970ea..fb54a45 100644 --- a/src/tree.rs +++ b/src/tree.rs @@ -248,7 +248,8 @@ impl Node { priority: 1, ..Node::default() }); - let has_suffix = !matches!(*suffix, b"" | b"/"); + let has_suffix = matches!(state.node().node_type, NodeType::Param { suffix: true }) + || !matches!(*suffix, b"" | b"/"); state.node_mut().node_type = NodeType::Param { suffix: has_suffix }; state = state.set_child(child); @@ -409,6 +410,10 @@ impl Node { /// Returns `true` if there is a wildcard node that contains a prefix within the current route segment, /// i.e. before the next trailing slash fn prefix_wild_child_in_segment(&self) -> bool { + if matches!(self.node_type, NodeType::Root) && self.prefix.is_empty() { + return false; + } + if self.prefix.ends_with(b"/") { self.children.iter().any(Node::prefix_wild_child_in_segment) } else { diff --git a/tests/insert.rs b/tests/insert.rs index b01ddbe..a6a800d 100644 --- a/tests/insert.rs +++ b/tests/insert.rs @@ -16,6 +16,12 @@ fn conflict(with: &'static str) -> InsertError { InsertError::Conflict { with: with.into() } } +// https://github.com/ibraheemdev/matchit/issues/84 +#[test] +fn root_prefix_issue() { + InsertTest(vec![("{foo}", Ok(())), ("{foo}suffix", Ok(()))]).run() +} + #[test] fn wildcard_conflict() { InsertTest(vec![ diff --git a/tests/match.rs b/tests/match.rs index 1edcb92..97b20f7 100644 --- a/tests/match.rs +++ b/tests/match.rs @@ -134,6 +134,16 @@ fn bare_catchall() { .run() } +// https://github.com/ibraheemdev/matchit/issues/83 +#[test] +fn param_suffix_flag_issue() { + MatchTest { + routes: vec!["/foo/{foo}suffix", "/foo/{foo}/bar"], + matches: vec![("/foo/barsuffix", "/foo/{foo}suffix", p! { "foo" => "bar" })], + } + .run() +} + #[test] fn normalized() { MatchTest {