Skip to content

Commit

Permalink
Merge branch 'treat_dot_as_xpath'
Browse files Browse the repository at this point in the history
  • Loading branch information
flavorjones committed Jun 7, 2012
2 parents 00bd62d + 6038226 commit 1558c97
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/nokogiri/xml/node.rb
Expand Up @@ -103,7 +103,7 @@ def search *paths

xpath(*(paths.map { |path|
path = path.to_s
path =~ /^(\.\/|\/|\.\.)/ ? path : CSS.xpath_for(
path =~ /^(\.\/|\/|\.\.|\.$)/ ? path : CSS.xpath_for(
path,
:prefix => prefix,
:ns => ns
Expand Down
2 changes: 1 addition & 1 deletion lib/nokogiri/xml/node_set.rb
Expand Up @@ -79,7 +79,7 @@ def search *paths

paths.each do |path|
sub_set += send(
path =~ /^(\.\/|\/)/ ? :xpath : :css,
path =~ /^(\.\/|\/|\.\.|\.$)/ ? :xpath : :css,
*(paths + [ns, handler]).compact
)
end
Expand Down
10 changes: 10 additions & 0 deletions test/xml/test_node.rb
Expand Up @@ -454,6 +454,11 @@ def test_at
assert_equal node, @xml.xpath('//address').first
end

def test_at_self
node = @xml.at('address')
assert_equal node, node.at('.')
end

def test_at_xpath
node = @xml.at_xpath('//address')
nodes = @xml.xpath('//address')
Expand Down Expand Up @@ -740,6 +745,11 @@ def test_parent_xpath
assert_equal node.parent, parent_node
end

def test_search_self
node = @xml.at('//employee')
assert_equal node.search('.').to_a, [node]
end

def test_search_by_symbol
assert set = @xml.search(:employee)
assert 5, set.length
Expand Down
5 changes: 5 additions & 0 deletions test/xml/test_node_set.rb
Expand Up @@ -146,6 +146,11 @@ def awesome ns
assert_equal @xml.xpath('//employee'), custom_employees
end

def test_search_self
set = @xml.xpath('//staff')
assert_equal set.to_a, set.search('.').to_a
end

def test_search_with_custom_object
set = @xml.xpath('//staff')
custom_employees = set.search('//*[awesome(.)]', Class.new {
Expand Down

0 comments on commit 1558c97

Please sign in to comment.