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
This commit should fix #29725.

Signed-off-by: Veronika Bušů <paricbat@email.cz>
  • Loading branch information
paricbat authored and mrobinson committed May 11, 2023
1 parent 419c031 commit e40ec79
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 20 deletions.
16 changes: 12 additions & 4 deletions components/script/dom/urlsearchparams.rs
Expand Up @@ -105,9 +105,14 @@ impl URLSearchParamsMethods for URLSearchParams {
}

// https://url.spec.whatwg.org/#dom-urlsearchparams-delete
fn Delete(&self, name: USVString) {
fn Delete(&self, name: USVString, value: Option<USVString>) {
// Step 1.
self.list.borrow_mut().retain(|&(ref k, _)| k != &name.0);
self.list
.borrow_mut()
.retain(|&(ref k, ref v)| match &value {
Some(value) => !(k == &name.0 && v == &value.0),
None => k != &name.0,
});
// Step 2.
self.update_steps();
}
Expand Down Expand Up @@ -135,9 +140,12 @@ impl URLSearchParamsMethods for URLSearchParams {
}

// https://url.spec.whatwg.org/#dom-urlsearchparams-has
fn Has(&self, name: USVString) -> bool {
fn Has(&self, name: USVString, value: Option<USVString>) -> bool {
let list = self.list.borrow();
list.iter().any(|&(ref k, _)| k == &name.0)
list.iter().any(|&(ref k, ref v)| match &value {
Some(value) => k == &name.0 && v == &value.0,
None => k == &name.0,
})
}

// https://url.spec.whatwg.org/#dom-urlsearchparams-set
Expand Down
4 changes: 2 additions & 2 deletions components/script/dom/webidls/URLSearchParams.webidl
Expand Up @@ -11,10 +11,10 @@ interface URLSearchParams {
[Throws] constructor(optional (sequence<sequence<USVString>> or record<USVString, USVString> or USVString) init = "");
readonly attribute unsigned long size;
undefined append(USVString name, USVString value);
undefined delete(USVString name);
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
6 changes: 0 additions & 6 deletions tests/wpt/metadata/url/urlsearchparams-delete.any.js.ini
Expand Up @@ -2,13 +2,7 @@
[Changing the query of a URL with an opaque path can impact the path]
expected: FAIL

[Two-argument delete()]
expected: FAIL


[urlsearchparams-delete.any.html]
[Changing the query of a URL with an opaque path can impact the path]
expected: FAIL

[Two-argument delete()]
expected: FAIL
8 changes: 0 additions & 8 deletions tests/wpt/metadata/url/urlsearchparams-has.any.js.ini

This file was deleted.

0 comments on commit e40ec79

Please sign in to comment.