Repository navigation
fix(@angular/build): match proxy glob patterns against URL pathname only - #34377
Conversation
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.
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
7f5b909 to
5b219b6
Compare
|
This pull request has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
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