mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-25 10:48:53 +00:00
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:
parent
9bf29356a2
commit
d5c6e45dca
Notes:
sideshowbarker
2024-07-17 06:40:21 +09:00
Author: https://github.com/kalenikaliaksandr
Commit: d5c6e45dca
Pull-request: https://github.com/SerenityOS/serenity/pull/23680
3 changed files with 15 additions and 4 deletions
1
Tests/LibWeb/Text/expected/DOM/Element-closest.txt
Normal file
1
Tests/LibWeb/Text/expected/DOM/Element-closest.txt
Normal file
|
@ -0,0 +1 @@
|
||||||
|
<DIV id="target" >
|
10
Tests/LibWeb/Text/input/DOM/Element-closest.html
Normal file
10
Tests/LibWeb/Text/input/DOM/Element-closest.html
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<script src="../include.js"></script>
|
||||||
|
<div class="a" id="target"><div id="nested"></div></div>
|
||||||
|
<script>
|
||||||
|
test(() => {
|
||||||
|
const matchingElement = document.getElementById("nested").closest(".a, .b, .c");
|
||||||
|
printElement(matchingElement);
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
</html>
|
|
@ -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) {
|
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.
|
// 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) {
|
for (auto const& selector : selector_list) {
|
||||||
if (!SelectorEngine::matches(selector, {}, *element, {}, this))
|
if (SelectorEngine::matches(selector, {}, *element, {}, this))
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
auto const selector_list = maybe_selectors.release_value();
|
auto const selector_list = maybe_selectors.release_value();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue