mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-03 16:16:43 +00:00
LibWeb: Implement value argument of URLSearchParams.delete
This commit is contained in:
parent
e2fb24c9b8
commit
5637dc43b2
Notes:
github-actions[bot]
2024-08-12 22:02:50 +00:00
Author: https://github.com/shannonbooth
Commit: 5637dc43b2
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1033
Reviewed-by: https://github.com/tcl3 ✅
5 changed files with 37 additions and 7 deletions
5
Tests/LibWeb/Text/expected/URL/search-params-delete.txt
Normal file
5
Tests/LibWeb/Text/expected/URL/search-params-delete.txt
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
animal=octopus&place=ocean
|
||||||
|
animal=octopus&place=ocean
|
||||||
|
place=ocean
|
||||||
|
place=ocean
|
||||||
|
|
15
Tests/LibWeb/Text/input/URL/search-params-delete.html
Normal file
15
Tests/LibWeb/Text/input/URL/search-params-delete.html
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
<script src="../include.js"></script>
|
||||||
|
<script>
|
||||||
|
test(() => {
|
||||||
|
const params = new URLSearchParams('animal=octopus&place=ocean');
|
||||||
|
println(params.toString());
|
||||||
|
params.delete('non-existing-key');
|
||||||
|
println(params.toString());
|
||||||
|
params.delete('animal');
|
||||||
|
println(params.toString());
|
||||||
|
params.delete('place', 'non-existing-value');
|
||||||
|
println(params.toString());
|
||||||
|
params.delete('place', 'ocean');
|
||||||
|
println(params.toString());
|
||||||
|
});
|
||||||
|
</script>
|
|
@ -231,12 +231,22 @@ WebIDL::ExceptionOr<void> URLSearchParams::update()
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
WebIDL::ExceptionOr<void> URLSearchParams::delete_(String const& name)
|
// https://url.spec.whatwg.org/#dom-urlsearchparams-delete
|
||||||
|
WebIDL::ExceptionOr<void> URLSearchParams::delete_(String const& name, Optional<String> const& value)
|
||||||
{
|
{
|
||||||
// 1. Remove all name-value pairs whose name is name from list.
|
// 1. If value is given, then remove all tuples whose name is name and value is value from this’s list.
|
||||||
m_list.remove_all_matching([&name](auto& entry) {
|
if (value.has_value()) {
|
||||||
return entry.name == name;
|
m_list.remove_all_matching([&name, &value](auto& entry) {
|
||||||
});
|
return entry.name == name && entry.value == value.value();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
// 2. Otherwise, remove all tuples whose name is name from this’s list.
|
||||||
|
else {
|
||||||
|
m_list.remove_all_matching([&name](auto& entry) {
|
||||||
|
return entry.name == name;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// 2. Update this.
|
// 2. Update this.
|
||||||
TRY(update());
|
TRY(update());
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,7 @@ public:
|
||||||
|
|
||||||
size_t size() const;
|
size_t size() const;
|
||||||
WebIDL::ExceptionOr<void> append(String const& name, String const& value);
|
WebIDL::ExceptionOr<void> append(String const& name, String const& value);
|
||||||
WebIDL::ExceptionOr<void> delete_(String const& name);
|
WebIDL::ExceptionOr<void> delete_(String const& name, Optional<String> const& value = {});
|
||||||
Optional<String> get(String const& name);
|
Optional<String> get(String const& name);
|
||||||
WebIDL::ExceptionOr<Vector<String>> get_all(String const& name);
|
WebIDL::ExceptionOr<Vector<String>> get_all(String const& name);
|
||||||
bool has(String const& name);
|
bool has(String const& name);
|
||||||
|
|
|
@ -7,7 +7,7 @@ interface URLSearchParams {
|
||||||
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);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue