Skip to content

Truly independent web browser

LibWeb: Parse the resulting query in the URL search setter

Shannon Booth8fbe8f3a163d
diff --git a/Libraries/LibWeb/DOMURL/DOMURL.cpp b/Libraries/LibWeb/DOMURL/DOMURL.cpp
index 027f64afde4..199c69910c0 100644
--- a/Libraries/LibWeb/DOMURL/DOMURL.cpp
+++ b/Libraries/LibWeb/DOMURL/DOMURL.cpp
@@ -392,9 +392,9 @@ void DOMURL::set_search(Utf16String const& search)
// 5. Basic URL parse input with url as url and query state as state override.
(void)URL::Parser::basic_parse(input, url, URL::Parser::State::Query);
- // 6. Set this’s query object’s list to the result of parsing input.
+ // 6. Set this’s query object’s list to the result of parsing url’s query.
if (m_query)
- m_query->m_list = url_decode(input);
+ m_query->m_list = url_decode(*url.query());
}
// https://url.spec.whatwg.org/#dom-url-searchparams
diff --git a/Tests/LibWeb/Text/expected/wpt-import/url/url-setters-stripping.any.txt b/Tests/LibWeb/Text/expected/wpt-import/url/url-setters-stripping.any.txt
index 394cba2529b..0ce81a1959b 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/url/url-setters-stripping.any.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/url/url-setters-stripping.any.txt
@@ -1,8 +1,8 @@
Harness status: OK
-Found 260 tests
+Found 320 tests
-260 Pass
+320 Pass
Pass Setting protocol with leading U+0000 (https:)
Pass Setting protocol with U+0000 before inserted colon (https:)
Pass Setting username with leading U+0000 (https:)
@@ -29,6 +29,12 @@ Pass Setting search with trailing U+0000 (https:)
Pass Setting hash with leading U+0000 (https:)
Pass Setting hash with middle U+0000 (https:)
Pass Setting hash with trailing U+0000 (https:)
+Pass Setting search with leading U+0000 updates searchParams (https:)
+Pass Setting search with leading U+0000 updates previously obtained searchParams (https:)
+Pass Setting search with middle U+0000 updates searchParams (https:)
+Pass Setting search with middle U+0000 updates previously obtained searchParams (https:)
+Pass Setting search with trailing U+0000 updates searchParams (https:)
+Pass Setting search with trailing U+0000 updates previously obtained searchParams (https:)
Pass Setting protocol with leading U+0009 (https:)
Pass Setting protocol with U+0009 before inserted colon (https:)
Pass Setting username with leading U+0009 (https:)
@@ -55,6 +61,12 @@ Pass Setting search with trailing U+0009 (https:)
Pass Setting hash with leading U+0009 (https:)
Pass Setting hash with middle U+0009 (https:)
Pass Setting hash with trailing U+0009 (https:)
+Pass Setting search with leading U+0009 updates searchParams (https:)
+Pass Setting search with leading U+0009 updates previously obtained searchParams (https:)
+Pass Setting search with middle U+0009 updates searchParams (https:)
+Pass Setting search with middle U+0009 updates previously obtained searchParams (https:)
+Pass Setting search with trailing U+0009 updates searchParams (https:)
+Pass Setting search with trailing U+0009 updates previously obtained searchParams (https:)
Pass Setting protocol with leading U+000A (https:)
Pass Setting protocol with U+000A before inserted colon (https:)
Pass Setting username with leading U+000A (https:)
@@ -81,6 +93,12 @@ Pass Setting search with trailing U+000A (https:)
Pass Setting hash with leading U+000A (https:)
Pass Setting hash with middle U+000A (https:)
Pass Setting hash with trailing U+000A (https:)
+Pass Setting search with leading U+000A updates searchParams (https:)
+Pass Setting search with leading U+000A updates previously obtained searchParams (https:)
+Pass Setting search with middle U+000A updates searchParams (https:)
+Pass Setting search with middle U+000A updates previously obtained searchParams (https:)
+Pass Setting search with trailing U+000A updates searchParams (https:)
+Pass Setting search with trailing U+000A updates previously obtained searchParams (https:)
Pass Setting protocol with leading U+000D (https:)
Pass Setting protocol with U+000D before inserted colon (https:)
Pass Setting username with leading U+000D (https:)
@@ -107,6 +125,12 @@ Pass Setting search with trailing U+000D (https:)
Pass Setting hash with leading U+000D (https:)
Pass Setting hash with middle U+000D (https:)
Pass Setting hash with trailing U+000D (https:)
+Pass Setting search with leading U+000D updates searchParams (https:)
+Pass Setting search with leading U+000D updates previously obtained searchParams (https:)
+Pass Setting search with middle U+000D updates searchParams (https:)
+Pass Setting search with middle U+000D updates previously obtained searchParams (https:)
+Pass Setting search with trailing U+000D updates searchParams (https:)
+Pass Setting search with trailing U+000D updates previously obtained searchParams (https:)
Pass Setting protocol with leading U+001F (https:)
Pass Setting protocol with U+001F before inserted colon (https:)
Pass Setting username with leading U+001F (https:)
@@ -133,6 +157,12 @@ Pass Setting search with trailing U+001F (https:)
Pass Setting hash with leading U+001F (https:)
Pass Setting hash with middle U+001F (https:)
Pass Setting hash with trailing U+001F (https:)
+Pass Setting search with leading U+001F updates searchParams (https:)
+Pass Setting search with leading U+001F updates previously obtained searchParams (https:)
+Pass Setting search with middle U+001F updates searchParams (https:)
+Pass Setting search with middle U+001F updates previously obtained searchParams (https:)
+Pass Setting search with trailing U+001F updates searchParams (https:)
+Pass Setting search with trailing U+001F updates previously obtained searchParams (https:)
Pass Setting protocol with leading U+0000 (wpt++:)
Pass Setting protocol with U+0000 before inserted colon (wpt++:)
Pass Setting username with leading U+0000 (wpt++:)
@@ -159,6 +189,12 @@ Pass Setting search with trailing U+0000 (wpt++:)
Pass Setting hash with leading U+0000 (wpt++:)
Pass Setting hash with middle U+0000 (wpt++:)
Pass Setting hash with trailing U+0000 (wpt++:)
+Pass Setting search with leading U+0000 updates searchParams (wpt++:)
+Pass Setting search with leading U+0000 updates previously obtained searchParams (wpt++:)
+Pass Setting search with middle U+0000 updates searchParams (wpt++:)
+Pass Setting search with middle U+0000 updates previously obtained searchParams (wpt++:)
+Pass Setting search with trailing U+0000 updates searchParams (wpt++:)
+Pass Setting search with trailing U+0000 updates previously obtained searchParams (wpt++:)
Pass Setting protocol with leading U+0009 (wpt++:)
Pass Setting protocol with U+0009 before inserted colon (wpt++:)
Pass Setting username with leading U+0009 (wpt++:)
@@ -185,6 +221,12 @@ Pass Setting search with trailing U+0009 (wpt++:)
Pass Setting hash with leading U+0009 (wpt++:)
Pass Setting hash with middle U+0009 (wpt++:)
Pass Setting hash with trailing U+0009 (wpt++:)
+Pass Setting search with leading U+0009 updates searchParams (wpt++:)
+Pass Setting search with leading U+0009 updates previously obtained searchParams (wpt++:)
+Pass Setting search with middle U+0009 updates searchParams (wpt++:)
+Pass Setting search with middle U+0009 updates previously obtained searchParams (wpt++:)
+Pass Setting search with trailing U+0009 updates searchParams (wpt++:)
+Pass Setting search with trailing U+0009 updates previously obtained searchParams (wpt++:)
Pass Setting protocol with leading U+000A (wpt++:)
Pass Setting protocol with U+000A before inserted colon (wpt++:)
Pass Setting username with leading U+000A (wpt++:)
@@ -211,6 +253,12 @@ Pass Setting search with trailing U+000A (wpt++:)
Pass Setting hash with leading U+000A (wpt++:)
Pass Setting hash with middle U+000A (wpt++:)
Pass Setting hash with trailing U+000A (wpt++:)
+Pass Setting search with leading U+000A updates searchParams (wpt++:)
+Pass Setting search with leading U+000A updates previously obtained searchParams (wpt++:)
+Pass Setting search with middle U+000A updates searchParams (wpt++:)
+Pass Setting search with middle U+000A updates previously obtained searchParams (wpt++:)
+Pass Setting search with trailing U+000A updates searchParams (wpt++:)
+Pass Setting search with trailing U+000A updates previously obtained searchParams (wpt++:)
Pass Setting protocol with leading U+000D (wpt++:)
Pass Setting protocol with U+000D before inserted colon (wpt++:)
Pass Setting username with leading U+000D (wpt++:)
@@ -237,6 +285,12 @@ Pass Setting search with trailing U+000D (wpt++:)
Pass Setting hash with leading U+000D (wpt++:)
Pass Setting hash with middle U+000D (wpt++:)
Pass Setting hash with trailing U+000D (wpt++:)
+Pass Setting search with leading U+000D updates searchParams (wpt++:)
+Pass Setting search with leading U+000D updates previously obtained searchParams (wpt++:)
+Pass Setting search with middle U+000D updates searchParams (wpt++:)
+Pass Setting search with middle U+000D updates previously obtained searchParams (wpt++:)
+Pass Setting search with trailing U+000D updates searchParams (wpt++:)
+Pass Setting search with trailing U+000D updates previously obtained searchParams (wpt++:)
Pass Setting protocol with leading U+001F (wpt++:)
Pass Setting protocol with U+001F before inserted colon (wpt++:)
Pass Setting username with leading U+001F (wpt++:)
@@ -262,4 +316,10 @@ Pass Setting search with middle U+001F (wpt++:)
Pass Setting search with trailing U+001F (wpt++:)
Pass Setting hash with leading U+001F (wpt++:)
Pass Setting hash with middle U+001F (wpt++:)
-Pass Setting hash with trailing U+001F (wpt++:)
\ No newline at end of file
+Pass Setting hash with trailing U+001F (wpt++:)
+Pass Setting search with leading U+001F updates searchParams (wpt++:)
+Pass Setting search with leading U+001F updates previously obtained searchParams (wpt++:)
+Pass Setting search with middle U+001F updates searchParams (wpt++:)
+Pass Setting search with middle U+001F updates previously obtained searchParams (wpt++:)
+Pass Setting search with trailing U+001F updates searchParams (wpt++:)
+Pass Setting search with trailing U+001F updates previously obtained searchParams (wpt++:)
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/input/wpt-import/url/url-setters-stripping.any.js b/Tests/LibWeb/Text/input/wpt-import/url/url-setters-stripping.any.js
index ac90cc17e0b..ff91aea8725 100644
--- a/Tests/LibWeb/Text/input/wpt-import/url/url-setters-stripping.any.js
+++ b/Tests/LibWeb/Text/input/wpt-import/url/url-setters-stripping.any.js
@@ -121,5 +121,26 @@ for(const scheme of ["https", "wpt++"]) {
}, `Setting ${property} with ${type} ${cpReference} (${scheme}:)`);
}
}
+
+ // searchParams has to reflect the resulting query, also when it was obtained before setting
+ // search
+ for (const [type, input] of [
+ ["leading", String.fromCodePoint(i) + "test"],
+ ["middle", "te" + String.fromCodePoint(i) + "st"],
+ ["trailing", "test" + String.fromCodePoint(i)]
+ ]) {
+ for (const searchParamsFirst of [false, true]) {
+ test(() => {
+ const expected = stripped ? "test" : input;
+ const url = urlRecord(scheme);
+ if (searchParamsFirst) {
+ url.searchParams;
+ }
+ url.search = input;
+ assert_array_equals([...url.searchParams.keys()], [expected], "keys");
+ assert_array_equals([...url.searchParams.values()], [""], "values");
+ }, `Setting search with ${type} ${cpReference} updates ${searchParamsFirst ? "previously obtained " : ""}searchParams (${scheme}:)`);
+ }
+ }
}
}