LibWeb: Change Element::closest() to check if any of selector matches

...instead of checking if all selectors match an element.

Fixes bug reduced from GitHub's "new issue" page.
This commit is contained in:
Aliaksandr Kalenik 2024-03-22 17:53:58 +01:00 committed by Andreas Kling
commit d5c6e45dca
Notes: sideshowbarker 2024-07-17 06:40:21 +09:00
3 changed files with 15 additions and 4 deletions

View file

@ -678,11 +678,11 @@ WebIDL::ExceptionOr<DOM::Element const*> Element::closest(StringView selectors)
auto matches_selectors = [this](CSS::SelectorList const& selector_list, Element const* element) {
// 4. For each element in elements, if match a selector against an element, using s, element, and scoping root this, returns success, return element.
for (auto& selector : selector_list) {
if (!SelectorEngine::matches(selector, {}, *element, {}, this))
return false;
for (auto const& selector : selector_list) {
if (SelectorEngine::matches(selector, {}, *element, {}, this))
return true;
}
return true;
return false;
};
auto const selector_list = maybe_selectors.release_value();