fix(jitsu-js): keep the event when the page URL has a stray % by breken-ai · Pull Request #1537 · jitsucom/jitsu · GitHub
Skip to content

fix(jitsu-js): keep the event when the page URL has a stray % - #1537

Open
breken-ai wants to merge 1 commit into
jitsucom:newjitsufrom
breken-ai:fix/js-malformed-query-percent
Open

breken-ai wants to merge 1 commit into
jitsucom:newjitsufrom
breken-ai:fix/js-malformed-query-percent

Conversation

@breken-ai

Copy link
Copy Markdown

What breaks

If the page URL has a bare % in its query string, @jitsu/js drops the event. For example https://shop.example.com/sale?discount=50%&utm_source=newsletter. Browsers keep a bare % as-is in location.href, and new URL() does too.

adjustPayload → parseQuery calls decodeURIComponent on every key and value. decodeURIComponent("50%") throws URIError: URI malformed, so send() rejects before the fetch. The plugin swallows the rejection with promise.catch(() => {}), so nothing is sent and nothing is logged. In the Node test below, the track() promise also never settles. Every page/track/identify call on that URL is lost, including the UTM campaign data.

Fix

parseQuery now uses a small safeDecodeURIComponent: it tries decodeURIComponent and falls back to the raw string. Well-formed values decode exactly as before.

Tests

New cases in libs/jitsu-js/__tests__/node/nodejs.test.ts:

  • a stray % in the page URL does not drop the event: uses a runtime whose pageUrl() has ?discount=50%&utm_source=newsletter. It checks that the local test server receives the event with context.campaign = { source: "newsletter" }.
  • parseQuery keeps malformed percent-encoding as is

Without the fix: expected +0 to be 1 (no request reached the server) and URIError: URI malformed. With the fix, the full @jitsu/js vitest suite passes (17/17). tsc --noEmit and prettier are clean.

This was found and fixed by an AI agent (Breken) and checked with the repo's own test suite.

parseQuery called decodeURIComponent on every query value. A bare % in the
page URL (e.g. ?discount=50%) throws URIError there, adjustPayload fails, and
the event is never sent. Malformed values are now kept as they are.

This branch has not been deployed

No deployments
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.

1 participant