From 4383dc62a1fe2f9167ab3abf482d641dbf15dc76 Mon Sep 17 00:00:00 2001 From: Yamagishi Kazutoshi Date: Tue, 12 Mar 2013 16:00:33 +0900 Subject: [PATCH] Add feature that the ':only-child' pseudo class should work even though it's in ':not' pseudo class. --- lib/nokogiri/css/xpath_visitor.rb | 1 + test/css/test_xpath_visitor.rb | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/lib/nokogiri/css/xpath_visitor.rb b/lib/nokogiri/css/xpath_visitor.rb index ae627a4814..7559f57019 100644 --- a/lib/nokogiri/css/xpath_visitor.rb +++ b/lib/nokogiri/css/xpath_visitor.rb @@ -109,6 +109,7 @@ def visit_pseudo_class node when "last", "last-child" then "position() = last()" when "first-of-type" then "position() = 1" when "last-of-type" then "position() = last()" + when "only-child" then "last() = 1" when "only-of-type" then "last() = 1" when "empty" then "not(node())" when "parent" then "node()" diff --git a/test/css/test_xpath_visitor.rb b/test/css/test_xpath_visitor.rb index b07626048d..fbbb677fe2 100644 --- a/test/css/test_xpath_visitor.rb +++ b/test/css/test_xpath_visitor.rb @@ -17,6 +17,11 @@ def test_not_last_child @parser.parse('ol > *:not(:last-child)')) end + def test_not_only_child + assert_xpath('//ol/*[not(last() = 1)]', + @parser.parse('ol > *:not(:only-child)')) + end + def test_function_calls_allow_at_params assert_xpath("//a[foo(., @href)]", @parser.parse('a:foo(@href)')) assert_xpath("//a[foo(., @a, b)]", @parser.parse('a:foo(@a, b)'))