Add value argument to URLSearchParams's has() and delete()

This commit should fix #29725.

Signed-off-by: Veronika Bušů <paricbat@email.cz>
This commit is contained in:
Veronika Bušů 2023-05-08 19:47:29 +02:00 committed by Martin Robinson
parent 419c03182f
commit e40ec79f65
4 changed files with 14 additions and 20 deletions

View file

@ -105,9 +105,14 @@ impl URLSearchParamsMethods for URLSearchParams {
} }
// https://url.spec.whatwg.org/#dom-urlsearchparams-delete // https://url.spec.whatwg.org/#dom-urlsearchparams-delete
fn Delete(&self, name: USVString) { fn Delete(&self, name: USVString, value: Option<USVString>) {
// Step 1. // 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. // Step 2.
self.update_steps(); self.update_steps();
} }
@ -135,9 +140,12 @@ impl URLSearchParamsMethods for URLSearchParams {
} }
// https://url.spec.whatwg.org/#dom-urlsearchparams-has // 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(); 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 // https://url.spec.whatwg.org/#dom-urlsearchparams-set

View file

@ -11,10 +11,10 @@ interface URLSearchParams {
[Throws] constructor(optional (sequence<sequence<USVString>> or record<USVString, USVString> or USVString) init = ""); [Throws] constructor(optional (sequence<sequence<USVString>> or record<USVString, USVString> or USVString) init = "");
readonly attribute unsigned long size; readonly attribute unsigned long size;
undefined append(USVString name, USVString value); undefined append(USVString name, USVString value);
undefined delete(USVString name); undefined delete(USVString name, optional USVString value);
USVString? get(USVString name); USVString? get(USVString name);
sequence<USVString> getAll(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 set(USVString name, USVString value);
undefined sort(); undefined sort();

View file

@ -2,13 +2,7 @@
[Changing the query of a URL with an opaque path can impact the path] [Changing the query of a URL with an opaque path can impact the path]
expected: FAIL expected: FAIL
[Two-argument delete()]
expected: FAIL
[urlsearchparams-delete.any.html] [urlsearchparams-delete.any.html]
[Changing the query of a URL with an opaque path can impact the path] [Changing the query of a URL with an opaque path can impact the path]
expected: FAIL expected: FAIL
[Two-argument delete()]
expected: FAIL

View file

@ -1,8 +0,0 @@
[urlsearchparams-has.any.html]
[Two-argument has()]
expected: FAIL
[urlsearchparams-has.any.worker.html]
[Two-argument has()]
expected: FAIL