Repository navigation
Conversation
When normalizing proxy configurations for Vite, glob patterns are converted into regular expression strings using picomatch. Because picomatch builds regular expressions assuming the input is a file path and anchors them with `$`, whereas Vite tests regex proxy keys against `req.url` (which includes any query string), requests with query parameters could fail to match glob entries such as `/search/**` or `/api/*.json`, or inadvertently match wildcards against query string parameters. Adapt the generated regular expression so that wildcard tokens do not match across the `?` query delimiter and end-of-path anchors allow an optional query string after the matched pathname. Closes angular#34257
There was a problem hiding this comment.
Code Review
This pull request updates the dev-server proxy configuration to ensure that glob patterns are matched against the URL pathname portion of a request rather than matching across query string parameters. It introduces a helper function makeUrlRegExpFromGlob to convert glob patterns into regular expressions that allow optional query strings, and adds comprehensive unit tests to verify this behavior. The review feedback suggests improving the robustness of the regular expression used to match unescaped end-of-input anchors, and adding a fallback to tmpdir() in the unit tests to support running them in local environments where TEST_TMPDIR is not set.
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.
When normalizing proxy configurations for Vite, glob patterns are converted into regular expression strings using picomatch. Because picomatch builds regular expressions assuming the input is a file path and anchors them with
$, whereas Vite tests regex proxy keys againstreq.url(which includes any query string), requests with query parameters could fail to match glob entries such as/search/**or/api/*.json, or inadvertently match wildcards against query string parameters.Adapt the generated regular expression so that wildcard tokens do not match across the
?query delimiter and end-of-path anchors allow an optional query string after the matched pathname.Closes #34257