Skip to content

Commit

Permalink
Auto merge of #29726 - paricbat:urlsearchparams-has-delete, r=mrobinson
Browse files Browse the repository at this point in the history
Add value argument to URLSearchParams's has() and delete()

<!-- Please describe your changes on the following line: -->
My first attempt at contributing Rust code!
Add the value argument to `has()` and `done()` as in [the spec](https://url.spec.whatwg.org/#dom-urlsearchparams-delete).

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix  #29725 (GitHub issue number if applicable)

<!-- Either: -->
- [X] There are tests for these changes OR
- [ ] These changes do not require tests because ___

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
  • Loading branch information
bors-servo committed May 11, 2023
2 parents 818ee77 + e40ec79 commit 425b0fe
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 425b0fe

Please sign in to comment.