Skip to content

🐛 Preserve '?' in query and '#' in fragment when appending URL params - #40569

Open
RaphaelFakhri wants to merge 1 commit into
ampproject:mainfrom
RaphaelFakhri:fix-append-param-url-truncation
Open

RaphaelFakhri wants to merge 1 commit into
ampproject:mainfrom
RaphaelFakhri:fix-append-param-url-truncation

Conversation

@RaphaelFakhri

Copy link
Copy Markdown

appendEncodedParamStringToUrl split the URL with url.split('#', 2) and split('?', 2). String.prototype.split with a limit drops everything after the limit, so adding a parameter truncated URLs whose query contains ? (for example ?next=/cart?id=5) or whose fragment contains # (for example #/route#section).

This affects every caller of addParamToUrl, addParamsToUrl, and addMissingParamsToUrl, including link decoration with data-amp-addparams, the amp-analytics linker, and impression tracking.

The fix splits on the first # and the first ? with indexOf, keeping the rest of the URL intact. Output for URLs without extra ? or # is unchanged.

Tests: two new cases in test/unit/test-url.js cover a ? inside the query (append and add-to-front) and a # inside the fragment.

Fixes #40568

@CLAassistant

CLAassistant commented Nov 4, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

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.

Adding a URL parameter truncates URLs that contain a second ? or #

2 participants