Skip to content

:has() selector should match against all descendants, not just direct children #350

Description

@pivotal-benchmark

From http://api.jquery.com/has-selector/:

The expression $('div:has(p)') matches a <div> if a <p> exists anywhere among its descendants, not just as a direct child.

So I would expect:

Nokogiri::CSS.xpath_for("#outer:has(#inner)")  # => ["//*[@id = 'outer' and .//*[@id = 'inner']]"]

But, instead:

Nokogiri::CSS.xpath_for("#outer:has(#inner)")  # => ["//*[@id = 'outer' and *[@id = 'inner']]"]

which doesn't match:

<div id="outer">
  <div>
    <div id="inner"/>
  </div>
</div>

(I think that's the right way to match all descendants, but I'm not totally solid on XPath. It works in my testing.)

Activity

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

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions