feat(core): Add filterUrlQuery util - #23060
Conversation
|
buglitzer moch |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 78418c3. Configure here.
filterUrlQuery utilfilterUrlQuery util
size-limit report 📦
|
Applies a `CollectBehavior` to the query string of a URL, leaving every other part of the URL untouched. The query is located by string offset rather than by parsing, so encoding, duplicate keys and param order are preserved byte-for-byte. All filtering logic is delegated to the existing `filterQueryParams`. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
78418c3 to
c9eeb91
Compare
|
|
||
| const filtered = filterQueryParams(query, behavior); | ||
|
|
||
| return filtered ? `${prefix}?${filtered}${suffix}` : `${prefix}${suffix}`; |
There was a problem hiding this comment.
Bug: filterUrlQuery removes the trailing ? from URLs with empty query strings even when data collection is enabled, due to an ambiguous falsy check.
Severity: LOW
Suggested Fix
In filterUrlQuery, change the condition from filtered ? to a more explicit check like filtered !== undefined. This will differentiate between an empty query string (where filtered is undefined but the ? should be kept) and the case where collection is disabled (where filtered is also undefined and the ? should be removed).
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.
Location: packages/core/src/utils/data-collection/filterUrlQuery.ts#L30
Potential issue: The function `filterUrlQuery` incorrectly removes the trailing `?` from
a URL with an empty query string (e.g., `https://example.com/api?`) even when data
collection is enabled. This happens because `filterQueryParams` returns `undefined` for
an empty query string. The subsequent falsy check `filtered ?` in `filterUrlQuery`
cannot distinguish this `undefined` from the case where collection is explicitly
disabled, causing it to strip the `?`. This contradicts the documentation which states
the `?` is only removed when collection is off and undermines the PR's goal of
preserving URLs.
Did we get this right? 👍 / 👎 to inform future reviews.
|
|
||
| const prefix = url.slice(0, queryStart); | ||
| const query = url.slice(queryStart + 1, queryEnd); | ||
| const suffix = url.slice(queryEnd); |
There was a problem hiding this comment.
nit: maybe just call this fragment?
Adds a util that applies a
CollectBehaviorto the query string of a URL, leaving the rest of the URL alone.It finds the query by string offset instead of parsing the URL, so encoding, duplicate keys and param order stay byte-for-byte identical. All the actual filtering is delegated to the existing
filterQueryParams.No call sites yet — those come in the PR stacked on top of this one.