Skip to content

Sort URLSearchParams names by UTF-16 code units - #59465

Closed
Marve10s wants to merge 1 commit into
react:mainfrom
Marve10s:fix/url-search-params-sort
Closed

Marve10s wants to merge 1 commit into
react:mainfrom
Marve10s:fix/url-search-params-sort

Conversation

@Marve10s

Copy link
Copy Markdown
Contributor

Summary:

URLSearchParams.sort() currently uses localeCompare, so query names follow locale collation instead of the UTF-16 code-unit order required by the URL standard. Sorting the same parameters in React Native and a browser can therefore produce different query strings.

For example:

const params = new URLSearchParams('a=first&Z=upper&a=second&z=last&ä=umlaut');
params.sort();
params.toString();

On React Native 0.88.0 and main, this produces a=first&a=second&%C3%A4=umlaut&z=last&Z=upper in an English locale. The expected result is Z=upper&a=first&a=second&z=last&%C3%A4=umlaut.

Compare names directly as strings to use code-unit order, preserve duplicate values, and remove the collation dependency. This also lets the existing Fantom URL test exercise sorting again, which was omitted because its Hermes build lacks ICU collation support.

Changelog:

[GENERAL] [FIXED] - Sort URLSearchParams names in UTF-16 code-unit order instead of locale order.

Test Plan:

Ran the existing URL test file headlessly using the root Jest configuration with a temporary adapter. The adapter selects URL-itest.js and aliases only @react-native/fantom/src/setUpDefaultReactNativeEnvironment to an empty module, retaining Jest's environment setup and the real URL classes.

./node_modules/.bin/jest --config /tmp/rn-url-sort-jest.config.cjs --runInBand --watchman=false --runTestsByPath packages/react-native/Libraries/Blob/__tests__/URL-itest.js

All three tests pass. Against the original implementation, the existing URL test passes and both new sorting regressions fail. They cover mixed-case and accented names, duplicate values, and supplementary characters whose UTF-16 ordering differs from code-point ordering.

./node_modules/.bin/eslint --max-warnings 0 packages/react-native/Libraries/Blob/URLSearchParams.js packages/react-native/Libraries/Blob/__tests__/URL-itest.js
./node_modules/.bin/prettier --check packages/react-native/Libraries/Blob/URLSearchParams.js packages/react-native/Libraries/Blob/__tests__/URL-itest.js
npx --yes --package=flow-bin@0.337.0 flow focus-check --max-workers 2 packages/react-native/Libraries/Blob/URLSearchParams.js packages/react-native/Libraries/Blob/__tests__/URL-itest.js

ESLint, formatting, and focused Flow checking pass. Independent Node probes reproduce the failures on 0.88.0 and main. Substituting the comparator matches native URLSearchParams ordering and still works when localeCompare is forced to throw.

These are headless Node checks. The native Fantom runner, native builds, and full-repository checks were not run.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Oct 25, 2026
@facebook-github-tools facebook-github-tools Bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Oct 25, 2026
@meta-codesync

meta-codesync Bot commented Oct 26, 2026

Copy link
Copy Markdown

@javache has imported this pull request. If you are a Meta employee, you can view this in D127563127.

@meta-codesync meta-codesync Bot closed this in 778fef7 Oct 26, 2026
@react-native-bot

Copy link
Copy Markdown
Collaborator

This pull request was successfully merged by @Marve10s in 778fef7

When will my fix make it into a release? | How to file a pick request?

@react-native-bot react-native-bot added the Merged This PR has been merged. label Oct 26, 2026
@meta-codesync

meta-codesync Bot commented Oct 26, 2026

Copy link
Copy Markdown

@javache merged this pull request in 778fef7.

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

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged This PR has been merged. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants