[backport v1.3.x] fix(router): only strip basePath when it is a leading prefix#152
Merged
Conversation
* fix(router): only strip basePath when it is a leading prefix The router derived the route path by stripping basePath wherever it appeared via pathname.split(basePath), which dropped any segments before the first occurrence. A pathname like /x/api/test would then resolve onto the internal route /test even though it is not mounted under basePath. Strip basePath only when it is a leading, /-boundary prefix of the request pathname; pathnames outside basePath now resolve to a 404. Trailing slashes on basePath are normalized so /api/auth/ and /api/auth behave the same. * refactor(router): derive base path once and flatten path resolution Compute the trailing-slash-normalized base path once at router creation instead of on every request, and resolve the request path with guard-clause early returns. Behavior is unchanged. Add a regression test for a sibling prefix that matches without a "/" boundary. --------- Co-authored-by: Taesu <bytaesu@gmail.com> (cherry picked from commit de59505)
commit: |
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
Backport of #149 to
v1.3.x.