LibWeb: Sort URLSearchParams using UTF-16 code units

We were previously sorting using code points which could give the wrong
result for certain inputs.

Fixes the last two failing tests on:

https://wpt.live/url/urlsearchparams-sort.any.html
This commit is contained in:
Shannon Booth 2024-08-15 20:40:10 +12:00 committed by Andreas Kling
commit d56da8cf9a
Notes: github-actions[bot] 2024-08-17 05:45:28 +00:00
3 changed files with 31 additions and 13 deletions

View file

@ -0,0 +1,17 @@
<script src="../include.js"></script>
<script>
function escapeUnicode(str) {
return str.replace(/[\s\S]/g, function(c) {
return '\\u' + ('0000' + c.charCodeAt(0).toString(16)).slice(-4);
});
}
test(() => {
let params = new URLSearchParams("\uFFFD=x&\uFFFC&\uFFFD=a");
params.sort();
println(params.toString())
for (const [key, value] of params) {
println(`'${escapeUnicode(key)}' => '${escapeUnicode(value)}'`);
}
})
</script>