escape rootURL and baseURL before regexp in getURL#21492
Merged
NullVoxPopuli merged 2 commits intoJul 10, 2026
Conversation
NullVoxPopuli
requested changes
Jul 8, 2026
NullVoxPopuli
left a comment
Contributor
There was a problem hiding this comment.
thanks for submitting this PR! just a couple things
| Escapes any regular-expression metacharacters in `str` so it can be safely | ||
| interpolated into a `RegExp` and matched as a literal. | ||
| */ | ||
| export function escapeRegExp(str: string): string { |
Contributor
There was a problem hiding this comment.
https://caniuse.com/mdn-javascript_builtins_regexp_escape
we can't use this yet, but should document to delete this function once our minimum browser support all includes RegExp.escape
Contributor
Author
There was a problem hiding this comment.
Good call. Added a TODO on the helper pointing at the caniuse link so we drop it for RegExp.escape once our minimum browsers cover it.
Contributor
|
duplicate of #21436 |
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.
getURL in HistoryLocation and NoneLocation strips the configured rootURL and baseURL off location.pathname by dropping them straight into
new RegExp(^${rootURL}(?=/|$)), so any regex metacharacter in those values is matched as a pattern against the browser-controlled pathname instead of a literal. a prefix like/a.c/then strips/axc/secretdown to/secretand hands the router the wrong route, an unbalanced(throws a SyntaxError on every navigation, and a nested-quantifier prefix backtracks exponentially on a short path. this routes both values through a small escapeRegExp helper in location-utils so the prefixes only ever match literally, with tests covering the metacharacter case in both location classes.