Skip to content

fix(platform): preserve percent encoding in Url.setUrlParams and modifyUrlParams#6154

Open
Gdhanush-13 wants to merge 1 commit intoEffect-TS:mainfrom
Gdhanush-13:fix/url-modify-params-percent-encoding
Open

fix(platform): preserve percent encoding in Url.setUrlParams and modifyUrlParams#6154
Gdhanush-13 wants to merge 1 commit intoEffect-TS:mainfrom
Gdhanush-13:fix/url-modify-params-percent-encoding

Conversation

@Gdhanush-13
Copy link
Copy Markdown

What

Fixes #6153 - Url.modifyUrlParams converts %20 to + in query parameters, even when using an identity function.

Root Cause

Url.setUrlParams and Url.modifyUrlParams both use UrlParams.toString to serialize params back to a search string. UrlParams.toString delegates to new URLSearchParams(...).toString() which encodes spaces as + per the application/x-www-form-urlencoded spec. This is correct for form request bodies but wrong for URL query strings where %20 should be preserved.

Reproduction

const url = new URL('https://example.com?foo=bar%20baz');
const url2 = Url.modifyUrlParams(url, identity);
url.href === url2.href; // false! %20 became +

Fix

  • Added UrlParams.toPercentEncoded which uses encodeURIComponent (producing %20 for spaces)
  • Updated Url.setUrlParams and Url.modifyUrlParams to use toPercentEncoded instead of toString
  • Left UrlParams.toString unchanged for backward compatibility with application/x-www-form-urlencoded body encoding

Files Changed

  • packages/platform/src/UrlParams.ts - added toPercentEncoded
  • packages/platform/src/Url.ts - use toPercentEncoded in setUrlParams and modifyUrlParams

…fyUrlParams

UrlParams.toString uses URLSearchParams.toString() which converts
%20 to + per the application/x-www-form-urlencoded spec. This is
correct for form bodies but wrong for URL query strings where %20
encoding should be preserved.

Added UrlParams.toPercentEncoded which uses encodeURIComponent
(producing %20 for spaces) and use it in Url.setUrlParams and
Url.modifyUrlParams. The existing toString is left unchanged for
backward compatibility with form body encoding.

Fixes Effect-TS#6153
@Gdhanush-13 Gdhanush-13 requested a review from tim-smart as a code owner April 3, 2026 16:21
@github-project-automation github-project-automation bot moved this to Discussion Ongoing in PR Backlog Apr 3, 2026
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Apr 3, 2026

⚠️ No Changeset found

Latest commit: 9fd7013

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

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

Labels

None yet

Projects

Status: Discussion Ongoing

Development

Successfully merging this pull request may close these issues.

Url.modifyUrlParams doesn't preserve percent encoding of spaces

1 participant