Fix : invalid params when using ignore trailing slash #34
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.
Description
This PR fixes an issue related to the new "ignore trailing slash" feature. Unlike the "redirect trailing slash" option, when "ignore trailing slash" is enabled, the correct route handler is expected to be called with the appropriate parameters for the matched route. However, this wasn't always the case due to the evaluation of different paths with wildcard segments.
Problem
Given the following routes:
/api/{a}
/api/foo/{b}
When a request is made to
/api/foo/bar/
with "ignore trailing slash" enabled, the expected match is/api/foo/{b}
, but the parameters were not always correctly assigned. The evaluation process was as follows (also see priority rules):/api/foo/{b}
: Records "bar" as the parameter for{b}
, and marks it for a trailing slash recommendation (tsr
)./api/{a}
: Matches/api/foo
, drops{b}
parameter, and records "foo" as the parameter for{a}
.tsr
,/api/foo/{b}
, and calls the handler.During step 2, the parameters recorded in step 1 were lost, resulting in the correct handler being called but with incorrect parameters.
Solution
The fix ensures that parameters are preserved when encountering the first trailing slash recommendation (
tsr
). This way, when falling back to the initially matched route, the correct parameters are retained and passed to the handler.Benchmark Differential
Expect no impact on performance (small optimisation have been achieved on the lookup function.).