mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-01 13:49:16 +00:00
LibWeb: Use a stable sort for searching URLSearchParams
Quick sort is not a stable sort. This meant we had a subtle issue implementing this portion of the spec comment: > The relative order between name-value pairs with equal names must > be preserved. Switch to insertion sort which is a stable sort, and properly handles keys which are the same. Fixes 8 tests on https://wpt.live/url/urlsearchparams-sort.any.html
This commit is contained in:
parent
df4739d7ce
commit
1ba6dbd86c
Notes:
github-actions[bot]
2024-08-12 22:02:31 +00:00
Author: https://github.com/shannonbooth
Commit: 1ba6dbd86c
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1033
Reviewed-by: https://github.com/tcl3 ✅
3 changed files with 17 additions and 1 deletions
|
@ -0,0 +1,5 @@
|
||||||
|
=f&=t&=x&z=z
|
||||||
|
'' => 'f'
|
||||||
|
'' => 't'
|
||||||
|
'' => 'x'
|
||||||
|
'z' => 'z'
|
|
@ -0,0 +1,11 @@
|
||||||
|
<script src="../include.js"></script>
|
||||||
|
<script>
|
||||||
|
test(() => {
|
||||||
|
let params = new URLSearchParams("z=z&=f&=t&=x");
|
||||||
|
params.sort();
|
||||||
|
println(params.toString())
|
||||||
|
for (const [key, value] of params) {
|
||||||
|
println(`'${key}' => '${value}'`);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
</script>
|
|
@ -323,7 +323,7 @@ void URLSearchParams::set(String const& name, String const& value)
|
||||||
void URLSearchParams::sort()
|
void URLSearchParams::sort()
|
||||||
{
|
{
|
||||||
// 1. Sort all name-value pairs, if any, by their names. Sorting must be done by comparison of code units. The relative order between name-value pairs with equal names must be preserved.
|
// 1. Sort all name-value pairs, if any, by their names. Sorting must be done by comparison of code units. The relative order between name-value pairs with equal names must be preserved.
|
||||||
quick_sort(m_list.begin(), m_list.end(), [](auto& a, auto& b) {
|
insertion_sort(m_list, [](auto& a, auto& b) {
|
||||||
Utf8View a_code_points { a.name };
|
Utf8View a_code_points { a.name };
|
||||||
Utf8View b_code_points { b.name };
|
Utf8View b_code_points { b.name };
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue