mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-05 15:49:11 +00:00
LibWeb: Implement value argument of URLSearchParams.has
This commit is contained in:
parent
5637dc43b2
commit
264b5160c2
Notes:
github-actions[bot]
2024-08-12 22:02:45 +00:00
Author: https://github.com/shannonbooth
Commit: 264b5160c2
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1033
Reviewed-by: https://github.com/tcl3 ✅
5 changed files with 41 additions and 8 deletions
5
Tests/LibWeb/Text/expected/URL/search-params-has.txt
Normal file
5
Tests/LibWeb/Text/expected/URL/search-params-has.txt
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
false
|
||||||
|
true
|
||||||
|
false
|
||||||
|
true
|
||||||
|
false
|
11
Tests/LibWeb/Text/input/URL/search-params-has.html
Normal file
11
Tests/LibWeb/Text/input/URL/search-params-has.html
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
<script src="../include.js"></script>
|
||||||
|
<script>
|
||||||
|
test(() => {
|
||||||
|
const params = new URLSearchParams('animal=octopus&place=ocean');
|
||||||
|
println(params.has('non-existing-key'));
|
||||||
|
println(params.has('animal'));
|
||||||
|
println(params.has('place', 'non-existing-value'));
|
||||||
|
println(params.has('place', 'ocean'));
|
||||||
|
println(params.has('animal', 'ocean'));
|
||||||
|
});
|
||||||
|
</script>
|
|
@ -278,13 +278,30 @@ WebIDL::ExceptionOr<Vector<String>> URLSearchParams::get_all(String const& name)
|
||||||
return values;
|
return values;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool URLSearchParams::has(String const& name)
|
// https://url.spec.whatwg.org/#dom-urlsearchparams-has
|
||||||
|
bool URLSearchParams::has(String const& name, Optional<String> const& value)
|
||||||
{
|
{
|
||||||
// return true if there is a name-value pair whose name is name in this’s list, and false otherwise.
|
// 1. If value is given and there is a tuple whose name is name and value is value in this’s list, then return true.
|
||||||
return !m_list.find_if([&name](auto& entry) {
|
if (value.has_value()) {
|
||||||
|
if (!m_list.find_if([&name, &value](auto& entry) {
|
||||||
|
return entry.name == name && entry.value == value.value();
|
||||||
|
})
|
||||||
|
.is_end()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 2. If value is not given and there is a tuple whose name is name in this’s list, then return true.
|
||||||
|
else {
|
||||||
|
if (!m_list.find_if([&name](auto& entry) {
|
||||||
return entry.name == name;
|
return entry.name == name;
|
||||||
})
|
})
|
||||||
.is_end();
|
.is_end()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. Return false.
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
WebIDL::ExceptionOr<void> URLSearchParams::set(String const& name, String const& value)
|
WebIDL::ExceptionOr<void> URLSearchParams::set(String const& name, String const& value)
|
||||||
|
|
|
@ -35,7 +35,7 @@ public:
|
||||||
WebIDL::ExceptionOr<void> delete_(String const& name, Optional<String> const& value = {});
|
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, Optional<String> const& value = {});
|
||||||
WebIDL::ExceptionOr<void> set(String const& name, String const& value);
|
WebIDL::ExceptionOr<void> set(String const& name, String const& value);
|
||||||
|
|
||||||
WebIDL::ExceptionOr<void> sort();
|
WebIDL::ExceptionOr<void> sort();
|
||||||
|
|
|
@ -10,7 +10,7 @@ interface URLSearchParams {
|
||||||
undefined delete(USVString name, optional USVString value);
|
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();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue