Skip to content

feat(core): Add filterUrlQuery util - #23060

Open
chargome wants to merge 1 commit into
developfrom
fix/filter-url-query-util
Open

feat(core): Add filterUrlQuery util#23060
chargome wants to merge 1 commit into
developfrom
fix/filter-url-query-util

Conversation

@chargome

@chargome chargome commented Aug 5, 2026

Copy link
Copy Markdown
Member

Adds a util that applies a CollectBehavior to 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.

@chargome

chargome commented Aug 5, 2026

Copy link
Copy Markdown
Member Author

buglitzer moch

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ 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.

@chargome chargome changed the title fix(core): Add filterUrlQuery util feat(core): Add filterUrlQuery util Aug 5, 2026
@github-actions

github-actions Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size % Change Change
@sentry/browser 30.13 kB - -
@sentry/browser - with treeshaking flags 28.33 kB - -
@sentry/browser (incl. Tracing) 47.54 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 47.55 kB - -
@sentry/browser (incl. Tracing, Profiling) 52.29 kB - -
@sentry/browser (incl. Tracing, Replay) 86.92 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 76.33 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 91.61 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 104.25 kB - -
@sentry/browser (incl. Feedback) 47.45 kB - -
@sentry/browser (incl. sendFeedback) 34.97 kB - -
@sentry/browser (incl. FeedbackAsync) 40.11 kB - -
@sentry/browser (incl. Metrics) 31.2 kB - -
@sentry/browser (incl. Logs) 31.42 kB - -
@sentry/browser (incl. Metrics & Logs) 32.11 kB - -
@sentry/react 31.93 kB - -
@sentry/react (incl. Tracing) 49.8 kB - -
@sentry/vue 35.2 kB - -
@sentry/vue (incl. Tracing) 49.52 kB - -
@sentry/svelte 30.15 kB - -
CDN Bundle 32.14 kB - -
CDN Bundle (incl. Tracing) 47.82 kB - -
CDN Bundle (incl. Logs, Metrics) 33.68 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 49.19 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 73.02 kB - -
CDN Bundle (incl. Tracing, Replay) 85.46 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 86.77 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 91.27 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 92.59 kB - -
CDN Bundle - uncompressed 95.31 kB - -
CDN Bundle (incl. Tracing) - uncompressed 142.81 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 99.93 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 146.79 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 224.63 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 262.07 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 266.03 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 275.77 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 279.73 kB - -
@sentry/nextjs (client) 52.37 kB - -
@sentry/sveltekit (client) 47.99 kB - -
@sentry/core/server 65.55 kB - -
@sentry/core/browser 51.84 kB - -
@sentry/node 120.47 kB - -
@sentry/node/import (ESM hook with diagnostics-channel injection) 0 B added added
@sentry/node - without tracing 84.12 kB - -
@sentry/aws-serverless 92.61 kB - -
@sentry/cloudflare (withSentry) - minified 218.53 kB - -
@sentry/cloudflare (withSentry) 538.69 kB - -

View base workflow run

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>
@chargome
chargome force-pushed the fix/filter-url-query-util branch from 78418c3 to c9eeb91 Compare August 5, 2026 14:42
@chargome
chargome marked this pull request as ready for review August 5, 2026 15:01

const filtered = filterQueryParams(query, behavior);

return filtered ? `${prefix}?${filtered}${suffix}` : `${prefix}${suffix}`;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@nicohrubec nicohrubec left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice


const prefix = url.slice(0, queryStart);
const query = url.slice(queryStart + 1, queryEnd);
const suffix = url.slice(queryEnd);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: maybe just call this fragment?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants