Skip to content

filter() and is() match nothing for a positional pseudo-class left of a combinator (ul:first > li) #132

Open

Description

@gravitypdf-bot

Description of the bug

filter() and is() match nothing when a positional pseudo-class (:first, :eq(), …) sits on a compound to the left of a combinator. find() handles the same selector:

$xml = '<?xml version="1.0"?><root><ul id="u1"><li id="a"/><li id="b"/></ul><ul id="u2"><li id="c"/></ul></root>';

qp($xml)->find('ul:first > li');          // a, b
qp($xml, 'li')->filter('ul:first > li');  // (none), expected a, b
qp($xml, 'li')->is('ul:first > li');      // false, expected true
qp($xml, 'li')->filter('ul:eq(1) > li');  // (none), expected c

Cause

In initialized mode (the candidates are tested as themselves), DOMTraverser resolves a non-subject compound that carries a positional pseudo-class by searching the candidates' descendants instead of the document. Found during #128 (DOMTraverser::filterNodes()), which preserves the existing behaviour.

Expected

The same as jQuery's .filter(): a candidate matches if it is one of the elements find() would return for the selector from the document.

QueryPath version

main at 9d04ccf.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions