LibWeb: Ensure document.getElementsByClassName("") returns no elements

Previously, `document.getElementsByClassName("")` would return a
collection containing all elements in the given document.
This commit is contained in:
Tim Ledbetter 2024-07-22 21:17:17 +01:00 committed by Andreas Kling
commit 0fceede029
Notes: github-actions[bot] 2024-07-23 06:59:20 +00:00
4 changed files with 23 additions and 10 deletions

View file

@ -234,10 +234,10 @@ JS::NonnullGCPtr<HTMLCollection> ParentNode::get_elements_by_class_name(StringVi
}
return HTMLCollection::create(*this, HTMLCollection::Scope::Descendants, [list_of_class_names = move(list_of_class_names), quirks_mode = document().in_quirks_mode()](Element const& element) {
for (auto& name : list_of_class_names) {
if (!element.has_class(name, quirks_mode ? CaseSensitivity::CaseInsensitive : CaseSensitivity::CaseSensitive))
return false;
if (element.has_class(name, quirks_mode ? CaseSensitivity::CaseInsensitive : CaseSensitivity::CaseSensitive))
return true;
}
return true;
return false;
});
}