瀏覽代碼

LibWeb: Strip trailing spaces from opaque URL path on query change

This was added in https://github.com/whatwg/url/commit/fdaa0e5a
to fix a case where roundtrips could fail. We had already partially
implemented these steps - but it seems this was missed in the update of
URLSearchParams.

Fixes the last failing WPT test for:

https://wpt.live/url/urlsearchparams-delete.any.html
Shannon Booth 11 月之前
父節點
當前提交
cff3e78a14

+ 6 - 0
Tests/LibWeb/Text/expected/URL/search-params-strip-trailing-spaces-from-opaque-url.txt

@@ -0,0 +1,6 @@
+URL pathname is 'space    '
+URL href is 'data:space    ?test'
+true
+false
+URL pathname is 'space'
+URL href is 'data:space'

+ 16 - 0
Tests/LibWeb/Text/input/URL/search-params-strip-trailing-spaces-from-opaque-url.html

@@ -0,0 +1,16 @@
+<script src="../include.js"></script>
+<script>
+    test(() => {
+        const url = new URL('data:space    ?test');
+
+        println(`URL pathname is '${url.pathname}'`);
+        println(`URL href is '${url.href}'`);
+
+        println(url.searchParams.has('test'));
+        url.searchParams.delete('test');
+        println(url.searchParams.has('test'));
+
+        println(`URL pathname is '${url.pathname}'`);
+        println(`URL href is '${url.href}'`);
+    });
+</script>

+ 4 - 0
Userland/Libraries/LibWeb/DOMURL/URLSearchParams.cpp

@@ -229,6 +229,10 @@ void URLSearchParams::update()
 
     // 4. Set query’s URL object’s URL’s query to serializedQuery.
     m_url->set_query({}, move(serialized_query));
+
+    // 5. If serializedQuery is null, then potentially strip trailing spaces from an opaque path with query’s URL object.
+    if (!serialized_query.has_value())
+        strip_trailing_spaces_from_an_opaque_path(*m_url);
 }
 
 // https://url.spec.whatwg.org/#dom-urlsearchparams-delete