diff --git a/Tests/LibWeb/Text/expected/URL/search-params-delete.txt b/Tests/LibWeb/Text/expected/URL/search-params-delete.txt new file mode 100644 index 00000000000..34a40369c78 --- /dev/null +++ b/Tests/LibWeb/Text/expected/URL/search-params-delete.txt @@ -0,0 +1,5 @@ +animal=octopus&place=ocean +animal=octopus&place=ocean +place=ocean +place=ocean + diff --git a/Tests/LibWeb/Text/input/URL/search-params-delete.html b/Tests/LibWeb/Text/input/URL/search-params-delete.html new file mode 100644 index 00000000000..e2ba9c17fb6 --- /dev/null +++ b/Tests/LibWeb/Text/input/URL/search-params-delete.html @@ -0,0 +1,15 @@ + + diff --git a/Userland/Libraries/LibWeb/DOMURL/URLSearchParams.cpp b/Userland/Libraries/LibWeb/DOMURL/URLSearchParams.cpp index a6a2eaa28b1..89e35682315 100644 --- a/Userland/Libraries/LibWeb/DOMURL/URLSearchParams.cpp +++ b/Userland/Libraries/LibWeb/DOMURL/URLSearchParams.cpp @@ -231,12 +231,22 @@ WebIDL::ExceptionOr URLSearchParams::update() return {}; } -WebIDL::ExceptionOr URLSearchParams::delete_(String const& name) +// https://url.spec.whatwg.org/#dom-urlsearchparams-delete +WebIDL::ExceptionOr URLSearchParams::delete_(String const& name, Optional const& value) { - // 1. Remove all name-value pairs whose name is name from list. - m_list.remove_all_matching([&name](auto& entry) { - return entry.name == name; - }); + // 1. If value is given, then remove all tuples whose name is name and value is value from this’s list. + if (value.has_value()) { + 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. TRY(update()); diff --git a/Userland/Libraries/LibWeb/DOMURL/URLSearchParams.h b/Userland/Libraries/LibWeb/DOMURL/URLSearchParams.h index 2c732000e5d..e7440d6a273 100644 --- a/Userland/Libraries/LibWeb/DOMURL/URLSearchParams.h +++ b/Userland/Libraries/LibWeb/DOMURL/URLSearchParams.h @@ -32,7 +32,7 @@ public: size_t size() const; WebIDL::ExceptionOr append(String const& name, String const& value); - WebIDL::ExceptionOr delete_(String const& name); + WebIDL::ExceptionOr delete_(String const& name, Optional const& value = {}); Optional get(String const& name); WebIDL::ExceptionOr> get_all(String const& name); bool has(String const& name); diff --git a/Userland/Libraries/LibWeb/DOMURL/URLSearchParams.idl b/Userland/Libraries/LibWeb/DOMURL/URLSearchParams.idl index 3fce797ebfd..5226134f360 100644 --- a/Userland/Libraries/LibWeb/DOMURL/URLSearchParams.idl +++ b/Userland/Libraries/LibWeb/DOMURL/URLSearchParams.idl @@ -7,7 +7,7 @@ interface URLSearchParams { 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 getAll(USVString name); boolean has(USVString name);