Skip to content

Commit

Permalink
LibWeb: Make :nth-* selectors match children of non-elements
Browse files Browse the repository at this point in the history
This was covered by WPT, which caught us not allowing :nth-child(1)
to match the root HTML element, and other similar issues.
  • Loading branch information
awesomekling committed Nov 6, 2024
1 parent eeba30f commit 81e7553
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@ Rerun

Found 54 tests

30 Pass
24 Fail
46 Pass
8 Fail
Details
Result Test Name MessagePass Expected HTML element to match :first-child with matches, querySelector(), and querySelectorAll()
Pass Expected HTML element to match :last-child with matches, querySelector(), and querySelectorAll()
Pass Expected HTML element to match :only-child with matches, querySelector(), and querySelectorAll()
Pass Expected HTML element to match :first-of-type with matches, querySelector(), and querySelectorAll()
Pass Expected HTML element to match :last-of-type with matches, querySelector(), and querySelectorAll()
Pass Expected HTML element to match :only-of-type with matches, querySelector(), and querySelectorAll()
Fail Expected HTML element to match :nth-child(1) with matches, querySelector(), and querySelectorAll()
Fail Expected HTML element to match :nth-child(n) with matches, querySelector(), and querySelectorAll()
Fail Expected HTML element to match :nth-last-child(1) with matches, querySelector(), and querySelectorAll()
Fail Expected HTML element to match :nth-last-child(n) with matches, querySelector(), and querySelectorAll()
Fail Expected HTML element to match :nth-of-type(1) with matches, querySelector(), and querySelectorAll()
Fail Expected HTML element to match :nth-of-type(n) with matches, querySelector(), and querySelectorAll()
Fail Expected HTML element to match :nth-last-of-type(1) with matches, querySelector(), and querySelectorAll()
Fail Expected HTML element to match :nth-last-of-type(n) with matches, querySelector(), and querySelectorAll()
Pass Expected HTML element to match :nth-child(1) with matches, querySelector(), and querySelectorAll()
Pass Expected HTML element to match :nth-child(n) with matches, querySelector(), and querySelectorAll()
Pass Expected HTML element to match :nth-last-child(1) with matches, querySelector(), and querySelectorAll()
Pass Expected HTML element to match :nth-last-child(n) with matches, querySelector(), and querySelectorAll()
Pass Expected HTML element to match :nth-of-type(1) with matches, querySelector(), and querySelectorAll()
Pass Expected HTML element to match :nth-of-type(n) with matches, querySelector(), and querySelectorAll()
Pass Expected HTML element to match :nth-last-of-type(1) with matches, querySelector(), and querySelectorAll()
Pass Expected HTML element to match :nth-last-of-type(n) with matches, querySelector(), and querySelectorAll()
Pass Expected HTML element to not match :nth-child(2) with matches, querySelector(), and querySelectorAll()
Pass Expected HTML element to not match :nth-last-child(2) with matches, querySelector(), and querySelectorAll()
Pass Expected HTML element to not match :nth-of-type(2) with matches, querySelector(), and querySelectorAll()
Expand Down Expand Up @@ -51,14 +51,14 @@ Pass Expected DIV element to match :only-child with matches, querySelector(), an
Pass Expected DIV element to match :first-of-type with matches, querySelector(), and querySelectorAll()
Pass Expected DIV element to match :last-of-type with matches, querySelector(), and querySelectorAll()
Pass Expected DIV element to match :only-of-type with matches, querySelector(), and querySelectorAll()
Fail Expected DIV element to match :nth-child(1) with matches, querySelector(), and querySelectorAll()
Fail Expected DIV element to match :nth-child(n) with matches, querySelector(), and querySelectorAll()
Fail Expected DIV element to match :nth-last-child(1) with matches, querySelector(), and querySelectorAll()
Fail Expected DIV element to match :nth-last-child(n) with matches, querySelector(), and querySelectorAll()
Fail Expected DIV element to match :nth-of-type(1) with matches, querySelector(), and querySelectorAll()
Fail Expected DIV element to match :nth-of-type(n) with matches, querySelector(), and querySelectorAll()
Fail Expected DIV element to match :nth-last-of-type(1) with matches, querySelector(), and querySelectorAll()
Fail Expected DIV element to match :nth-last-of-type(n) with matches, querySelector(), and querySelectorAll()
Pass Expected DIV element to match :nth-child(1) with matches, querySelector(), and querySelectorAll()
Pass Expected DIV element to match :nth-child(n) with matches, querySelector(), and querySelectorAll()
Pass Expected DIV element to match :nth-last-child(1) with matches, querySelector(), and querySelectorAll()
Pass Expected DIV element to match :nth-last-child(n) with matches, querySelector(), and querySelectorAll()
Pass Expected DIV element to match :nth-of-type(1) with matches, querySelector(), and querySelectorAll()
Pass Expected DIV element to match :nth-of-type(n) with matches, querySelector(), and querySelectorAll()
Pass Expected DIV element to match :nth-last-of-type(1) with matches, querySelector(), and querySelectorAll()
Pass Expected DIV element to match :nth-last-of-type(n) with matches, querySelector(), and querySelectorAll()
Pass Expected DIV element to not match :nth-child(2) with matches, querySelector(), and querySelectorAll()
Pass Expected DIV element to not match :nth-last-child(2) with matches, querySelector(), and querySelectorAll()
Pass Expected DIV element to not match :nth-of-type(2) with matches, querySelector(), and querySelectorAll()
Expand Down
2 changes: 1 addition & 1 deletion Userland/Libraries/LibWeb/CSS/SelectorEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ static inline bool matches_pseudo_class(CSS::Selector::SimpleSelector::PseudoCla
if (step_size == 0 && offset == 0)
return false; // "If both a and b are equal to zero, the pseudo-class represents no element in the document tree."

auto const* parent = element.parent_element();
auto const* parent = element.parent();
if (!parent)
return false;

Expand Down

0 comments on commit 81e7553

Please sign in to comment.