Escape prefix value in hasBasename #604
Closed
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.
Closes #564
PathUtils.hasBasename
andPathUtils.stripBasename
hasBasename
:| \ { } ( ) [ ] ^ $ + * ? .
This PR fixes
PathUtils.hasBasename
so that it correctly handles special URL characters. This allows users to specify a basename that contains a search params and other special regex characters and have it both correctly match and correctly strip the basename from the path.This is helpful when you want to be able to ignore everything in the URL up to a given point. For example, given the URL
/basepath/app?search=params&to=ignore#/real/path/to/parse
, you may only care about/real/path/to/parse
. Providing a basename value of/basepath/app?search=params&to=ignore#/
would not previously work, because the?
was not escaped, so the produced RegExp inhasBasename
would not match correctly.This could be considered a breaking change if you were relying on the internal checking mechanism to use a regex pattern instead of a string. However, given that the docs specifically call for the basename value to be a string, I'd consider that an incorrect use of the basename value in the first place. From the README (emphasis mine):
Aside: The contributing guide says to add a note to CHANGES.md, but it seems that hasn't been done since
v4.6.3
, so I skipped that step... looks like most recent PRs haven't done this either.