Skip to content

Commit

Permalink
Add value argument to URLSearchParams's has() and delete()
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=256369
rdar://108949109

Reviewed by Chris Dumez.

Aligns WebKit with a recent URLSearchParams change.

Also syncs WPT url/ and new tests are upstreamed via web-platform-tests/wpt#39865.

* LayoutTests/imported/w3c/web-platform-tests/url/a-element-origin-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/url/a-element-origin-xhtml-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/url/a-element-xhtml_exclude=(file_javascript_mailto)-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/url/a-element_exclude=(file_javascript_mailto)-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/url/resources/urltestdata.json:
* LayoutTests/imported/w3c/web-platform-tests/url/url-constructor.any.worker_exclude=(file_javascript_mailto)-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/url/url-constructor.any_exclude=(file_javascript_mailto)-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/url/url-origin.any-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/url/url-origin.any.worker-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/url/urlsearchparams-delete.any-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/url/urlsearchparams-delete.any.js:
(test):
* LayoutTests/imported/w3c/web-platform-tests/url/urlsearchparams-delete.any.worker-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/url/urlsearchparams-has.any-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/url/urlsearchparams-has.any.js:
(test):
* LayoutTests/imported/w3c/web-platform-tests/url/urlsearchparams-has.any.worker-expected.txt:
* Source/WebCore/html/URLSearchParams.cpp:
(WebCore::URLSearchParams::has const):
(WebCore::URLSearchParams::remove):
* Source/WebCore/html/URLSearchParams.h:
(WebCore::URLSearchParams::remove):
(WebCore::URLSearchParams::has const):
* Source/WebCore/html/URLSearchParams.idl:

Canonical link: https://commits.webkit.org/263726@main
  • Loading branch information
annevk committed May 5, 2023
1 parent ccfcd8a commit 93a5678
Show file tree
Hide file tree
Showing 18 changed files with 57 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ PASS Parsing origin: <#> against <test:test>
PASS Parsing origin: <#x> against <mailto:x@x.com>
PASS Parsing origin: <#x> against <data:,>
PASS Parsing origin: <#x> against <about:blank>
PASS Parsing origin: <#x:y> against <about:blank>
PASS Parsing origin: <#> against <test:test?test>
PASS Parsing origin: <https://@test@test@example:800/> against <http://doesnotmatter/>
PASS Parsing origin: <https://@@@example> against <http://doesnotmatter/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ PASS Parsing origin: <#> against <test:test>
PASS Parsing origin: <#x> against <mailto:x@x.com>
PASS Parsing origin: <#x> against <data:,>
PASS Parsing origin: <#x> against <about:blank>
PASS Parsing origin: <#x:y> against <about:blank>
PASS Parsing origin: <#> against <test:test?test>
PASS Parsing origin: <https://@test@test@example:800/> against <http://doesnotmatter/>
PASS Parsing origin: <https://@@@example> against <http://doesnotmatter/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ PASS Parsing: <http://foo:💩@example.com/bar> against <http://other.com/>
PASS Parsing: <#> against <test:test>
FAIL Parsing: <#x> against <data:,> assert_equals: href expected "data:,#x" but got "test:test#x"
PASS Parsing: <#x> against <about:blank>
PASS Parsing: <#x:y> against <about:blank>
PASS Parsing: <#> against <test:test?test>
PASS Parsing: <https://@test@test@example:800/> against <http://doesnotmatter/>
PASS Parsing: <https://@@@example> against <http://doesnotmatter/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ PASS Parsing: <http://foo:💩@example.com/bar> against <http://other.com/>
PASS Parsing: <#> against <test:test>
FAIL Parsing: <#x> against <data:,> assert_equals: href expected "data:,#x" but got "test:test#x"
PASS Parsing: <#x> against <about:blank>
PASS Parsing: <#x:y> against <about:blank>
PASS Parsing: <#> against <test:test?test>
PASS Parsing: <https://@test@test@example:800/> against <http://doesnotmatter/>
PASS Parsing: <https://@@@example> against <http://doesnotmatter/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4066,6 +4066,21 @@
"search": "",
"hash": "#x"
},
{
"input": "#x:y",
"base": "about:blank",
"href": "about:blank#x:y",
"origin": "null",
"protocol": "about:",
"username": "",
"password": "",
"host": "",
"hostname": "",
"port": "",
"pathname": "blank",
"search": "",
"hash": "#x:y"
},
{
"input": "#",
"base": "test:test?test",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ PASS Parsing: <http://foo:💩@example.com/bar> against <http://other.com/>
PASS Parsing: <#> against <test:test>
PASS Parsing: <#x> against <data:,>
PASS Parsing: <#x> against <about:blank>
PASS Parsing: <#x:y> against <about:blank>
PASS Parsing: <#> against <test:test?test>
PASS Parsing: <https://@test@test@example:800/> against <http://doesnotmatter/>
PASS Parsing: <https://@@@example> against <http://doesnotmatter/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ PASS Parsing: <http://foo:💩@example.com/bar> against <http://other.com/>
PASS Parsing: <#> against <test:test>
PASS Parsing: <#x> against <data:,>
PASS Parsing: <#x> against <about:blank>
PASS Parsing: <#x:y> against <about:blank>
PASS Parsing: <#> against <test:test?test>
PASS Parsing: <https://@test@test@example:800/> against <http://doesnotmatter/>
PASS Parsing: <https://@@@example> against <http://doesnotmatter/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ PASS Origin parsing: <#> against <test:test>
PASS Origin parsing: <#x> against <mailto:x@x.com>
PASS Origin parsing: <#x> against <data:,>
PASS Origin parsing: <#x> against <about:blank>
PASS Origin parsing: <#x:y> against <about:blank>
PASS Origin parsing: <#> against <test:test?test>
PASS Origin parsing: <https://@test@test@example:800/> against <http://doesnotmatter/>
PASS Origin parsing: <https://@@@example> against <http://doesnotmatter/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ PASS Origin parsing: <#> against <test:test>
PASS Origin parsing: <#x> against <mailto:x@x.com>
PASS Origin parsing: <#x> against <data:,>
PASS Origin parsing: <#x> against <about:blank>
PASS Origin parsing: <#x:y> against <about:blank>
PASS Origin parsing: <#> against <test:test?test>
PASS Origin parsing: <https://@test@test@example:800/> against <http://doesnotmatter/>
PASS Origin parsing: <https://@@@example> against <http://doesnotmatter/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ PASS Deleting all params removes ? from URL
PASS Removing non-existent param removes ? from URL
PASS Changing the query of a URL with an opaque path can impact the path
PASS Changing the query of a URL with an opaque path can impact the path if the URL has no fragment
PASS Two-argument delete()

Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,12 @@ test(() => {
assert_equals(url.pathname, 'space ');
assert_equals(url.href, 'data:space #test');
}, 'Changing the query of a URL with an opaque path can impact the path if the URL has no fragment');

test(() => {
const params = new URLSearchParams();
params.append('a', 'b');
params.append('a', 'c');
params.append('a', 'd');
params.delete('a', 'c');
assert_equals(params.toString(), 'a=b&a=d');
}, "Two-argument delete()");
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ PASS Deleting all params removes ? from URL
PASS Removing non-existent param removes ? from URL
PASS Changing the query of a URL with an opaque path can impact the path
PASS Changing the query of a URL with an opaque path can impact the path if the URL has no fragment
PASS Two-argument delete()

Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

PASS Has basics
PASS has() following delete()
PASS Two-argument has()

Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,16 @@ test(function() {
params.delete('first');
assert_false(params.has('first'), 'Search params object has no name "first"');
}, 'has() following delete()');

test(() => {
const params = new URLSearchParams("a=b&a=d&c&e&");
assert_true(params.has('a', 'b'));
assert_false(params.has('a', 'c'));
assert_true(params.has('a', 'd'));
assert_true(params.has('e', ''));
params.append('first', null);
assert_false(params.has('first', ''));
assert_true(params.has('first', 'null'));
params.delete('a', 'b');
assert_true(params.has('a', 'd'));
}, "Two-argument has()");
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

PASS Has basics
PASS has() following delete()
PASS Two-argument has()

8 changes: 4 additions & 4 deletions Source/WebCore/html/URLSearchParams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ String URLSearchParams::get(const String& name) const
return String();
}

bool URLSearchParams::has(const String& name) const
bool URLSearchParams::has(const String& name, const String& value) const
{
for (const auto& pair : m_pairs) {
if (pair.key == name)
if (pair.key == name && (value.isNull() || pair.value == value))
return true;
}
return false;
Expand Down Expand Up @@ -126,10 +126,10 @@ Vector<String> URLSearchParams::getAll(const String& name) const
return values;
}

void URLSearchParams::remove(const String& name)
void URLSearchParams::remove(const String& name, const String& value)
{
m_pairs.removeAllMatching([&] (const auto& pair) {
return pair.key == name;
return pair.key == name && (value.isNull() || pair.value == value);
});
updateURL();
}
Expand Down
4 changes: 2 additions & 2 deletions Source/WebCore/html/URLSearchParams.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ class URLSearchParams : public RefCounted<URLSearchParams> {
size_t size() const { return m_pairs.size(); }

void append(const String& name, const String& value);
void remove(const String& name);
void remove(const String& name, const String& value = { });
String get(const String& name) const;
Vector<String> getAll(const String& name) const;
bool has(const String& name) const;
bool has(const String& name, const String& value = { }) const;
void set(const String& name, const String& value);
String toString() const;
void updateFromAssociatedURL();
Expand Down
4 changes: 2 additions & 2 deletions Source/WebCore/html/URLSearchParams.idl
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@
readonly attribute unsigned long size;

undefined append(USVString name, USVString value);
[ImplementedAs=remove] undefined delete(USVString name);
[ImplementedAs=remove] undefined delete(USVString name, optional USVString value);
USVString? get(USVString name);
sequence<USVString> getAll(USVString name);
boolean has(USVString name);
boolean has(USVString name, optional USVString value);
undefined set(USVString name, USVString value);

undefined sort();
Expand Down

0 comments on commit 93a5678

Please sign in to comment.