Add a regression test for url_search_params::sort taken from WPT #861
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
While working on integrating Web Platform Tests as a test suite for Cloudflare's worked, I discovered a situation where ada-url's implementation of url_search_params::sort appears not to be following the URL spec.
The URL spec provides the following requirements for URLSearchParams.sort:
— https://url.spec.whatwg.org/#example-searchparams-sort
WPT's urlsearchparams-sort.any.js test uses the following example to demonstrate this:
So the spec requires "comparsion of code units" but as far as I can tell, it isn't very clear about what encoding should be used to perform the comparsion. Based on the WPT test, and checking other implementations like Node and Chromium, the encoding used is UTF-16. This makes sense, as this matches the behaviour of Javascript's String type.
I can fix this by implementing something like
ada::idna::utf8_to_utf32
to do a conversion from utf8 to utf16 before sorting the keys, but please let me know if you have an alternative approach in mind - I'd be happy to implement it that way instead.