You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Child combinator throws TypeError when its right-hand side matches the document element (X > * always fails) #74
Any selector using the child combinator (>) whose right-hand side can also match the document element raises a TypeError from the selector engine. In practice this means X > * always fails, whatever X is, because * matches the root as well as everything else.
Uncaught TypeError: QueryPath\CSS\DOMTraverser::matchesSimpleSelector():
Argument #1 ($node) must be of type DOMElement, DOMDocument given
This affects qp(), htmlqp(), html5qp() and find() alike, since they all go through CSS\DOMTraverser.
Root cause
DOMTraverser::combineDirectDescendant() hands the parent node straight to matchesSimpleSelector() without checking its type (src/CSS/DOMTraverser.php:358-367):
matchesSimpleSelector() is typed DOMElement $node (src/CSS/DOMTraverser.php:207). When the right-hand selector matches the document element, $parent is the DOMDocument, and the type declaration rejects it.
combineAnyDescendant() immediately above already guards for this case:
if ($node->nodeType != XML_ELEMENT_NODE) {
continue;
}
which is why the descendant combinator (X *) works and the child combinator does not.
Fixed by #50 (745a4e2), which added a non-element guard to DOMTraverser::combineDirectDescendant(). X > * no longer throws on qp(), htmlqp() or html5qp(). A regression test for this case is on its way in a separate PR.
Activity
gravitypdf-bot commentedon Oct 26, 2026
Fixed by #50 (745a4e2), which added a non-element guard to
DOMTraverser::combineDirectDescendant().X > *no longer throws onqp(),htmlqp()orhtml5qp(). A regression test for this case is on its way in a separate PR.Add regression tests for combinators whose right-hand side matches th…