fix: normalize trailing slashes in middleware mount paths (#2281) - #203
Open
hanu-14 wants to merge 1 commit into
Open
fix: normalize trailing slashes in middleware mount paths (#2281)#203hanu-14 wants to merge 1 commit into
hanu-14 wants to merge 1 commit into
Conversation
Author
|
Friendly bump on this one. The fix normalizes trailing slashes in middleware mount paths so sub-routers with |
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.
Description
Strips trailing slashes from middleware mount paths in
Router.prototype.useto ensure consistent behavior with strict sub-routers. Fixes expressjs/express#2281.Problem
When mounting a strict sub-router at a path with a trailing slash (e.g.,
app.use("/foo/", strictRouter)), the trailing slash in the mount path could interfere with route matching under strict routing.The
loosen()function inlib/layer.jsalready strips trailing slashes viaTRAILING_SLASH_REGEXPbefore creating the regex pattern, andreq.baseUrlalready normalizes away trailing slashes intrimPrefix. This change makes the normalization explicit at the API boundary inRouter.prototype.use.Changes
trimPrefixthat tracked_mountConsumedTrailingSlash- theremovedvariable was always empty string at the check point, making the condition unreachable.Router.prototype.use- strips trailing slashes from middleware mount paths (e.g.,"/foo/"becomes"/foo"). Root path/and non-string paths are excluded.Testing
All 694 existing tests pass with 0 failures.
References