Skip to content

Commit bc1ac7a

Browse files
authored
fix prefix-suffix conflict due to insertion order of trailing slashes
When inserting route parameters with static suffixes, `matchit` checked for conflicts between newly inserted suffixes and existing ones. It had an explicit exception to allow a new suffix that only differed by an extra trailing slash (e.g., `o/` vs existing `o`). However, this check only evaluated one direction: if the *new* suffix was longer than the *existing* suffix. If the routes were inserted in the reverse order (e.g., `o/` inserted first, then `o` inserted second), the router incorrectly flagged them as a prefix-suffix conflict. This commit makes the trailing slash check bidirectional by adding an `else` branch to verify if the *existing* suffix is the one with the extra trailing slash, resolving the insertion order dependency.
1 parent 500698f commit bc1ac7a

2 files changed

Lines changed: 9 additions & 0 deletions

File tree

src/tree.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,11 @@ impl<T> Node<T> {
223223
if *common == *child.prefix && remaining == *b"/" {
224224
extra_trailing_slash = true;
225225
}
226+
} else {
227+
let (common, remaining) = child.prefix.split_at(suffix.len());
228+
if *common == **suffix && remaining == *b"/" {
229+
extra_trailing_slash = true;
230+
}
226231
}
227232
}
228233

tests/insert.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,10 @@ fn prefix_suffix_conflict() {
257257
("/x16/prefix{a}suffix", Ok(())),
258258
("/x17/prefix{a}/z", Ok(())),
259259
("/x18/prefix{a}/z", Ok(())),
260+
("/x19/f{a}o", Ok(())),
261+
("/x19/f{a}o/{*path}", Ok(())),
262+
("/x20/f{a}o/{*path}", Ok(())),
263+
("/x20/f{a}o", Ok(())),
260264
])
261265
.run()
262266
}

0 commit comments

Comments
 (0)