Skip to content

Commit

Permalink
CSS selector :has() matches against deep descendants
Browse files Browse the repository at this point in the history
Fixes #350.
  • Loading branch information
flavorjones committed Jan 5, 2019
1 parent a684202 commit c7fc1dc
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Expand Up @@ -7,6 +7,11 @@
* [MRI] Handle Xcode 10's new library path on macOS. [#1801, #1851] (Thanks, @mlj and @deepj!)


### Bug fixes

* CSS selector `:has()` correctly matches against any descendant (previously matched against only direct children). [#350] (Thanks, @Phrogz!)


## 1.10.0 / 2019-01-04

### Features
Expand Down
2 changes: 1 addition & 1 deletion lib/nokogiri/css/xpath_visitor.rb
Expand Up @@ -51,7 +51,7 @@ def visit_function node
when /^comment\(/
"comment()"
when /^has\(/
node.value[1].accept(self)
".//#{node.value[1].accept(self)}"
else
args = ['.'] + node.value[1..-1]
"#{node.value.first}#{args.join(', ')})"
Expand Down
4 changes: 2 additions & 2 deletions test/css/test_parser.rb
Expand Up @@ -63,8 +63,8 @@ def test_to_a
end

def test_has
assert_xpath "//a[b]", @parser.parse("a:has(b)")
assert_xpath "//a[b/c]", @parser.parse("a:has(b > c)")
assert_xpath "//a[.//b]", @parser.parse("a:has(b)")
assert_xpath "//a[.//b/c]", @parser.parse("a:has(b > c)")
end

def test_dashmatch
Expand Down

0 comments on commit c7fc1dc

Please sign in to comment.