Fix prefix-suffix conflict due to insertion order of trailing slashes#91
Open
Lencerf wants to merge 2 commits intoibraheemdev:masterfrom
Open
Fix prefix-suffix conflict due to insertion order of trailing slashes#91Lencerf wants to merge 2 commits intoibraheemdev:masterfrom
Lencerf wants to merge 2 commits intoibraheemdev:masterfrom
Conversation
Add test cases to unveil an issue where the order of adding routes like
/x20/f{a}o/{*path} and /x20/f{a}o could result in a conflict.
Signed-off-by: Changyuan Lyu <changyuanl@google.com>
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. Signed-off-by: Changyuan Lyu <changyuanl@google.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR tries to solve the following failure,
matchit_test1can pass butmatchit_test2fails with a conflict.When inserting route parameters with static suffixes,
matchitchecked 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 existingo).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, thenoinserted second), the router incorrectly flagged them as a prefix-suffix conflict.This commit makes the trailing slash check bidirectional by adding an
elsebranch to verify if the existing suffix is the one with the extra trailing slash, resolving the insertion order dependency.This PR is created with Gemini with the prompt of analyzing and fixing test case
matchit_test2.