XPath "self" axis inside predicates.

The "self" axis should use the current context node when inside a predicate.
This commit is contained in:
Yorick Peterse 2014-09-03 09:40:17 +02:00
parent 71f2b42074
commit 2b96d65103
2 changed files with 19 additions and 3 deletions

View File

@ -490,8 +490,12 @@ module Oga
def on_axis_self(ast_node, context)
nodes = XML::NodeSet.new
context.each do |context_node|
nodes << context_node if node_matches?(context_node, ast_node)
if current_node
nodes << current_node if node_matches?(current_node, ast_node)
else
context.each do |context_node|
nodes << context_node if node_matches?(context_node, ast_node)
end
end
return nodes

View File

@ -3,7 +3,7 @@ require 'spec_helper'
describe Oga::XPath::Evaluator do
context 'self axis' do
before do
@document = parse('<a></a>')
@document = parse('<a><b>foo</b><b>bar</b></a>')
@evaluator = described_class.new(@document)
end
@ -38,5 +38,17 @@ describe Oga::XPath::Evaluator do
@set[0].should == @document.children[0]
end
end
context 'matching nodes inside predicates' do
before do
@set = @evaluator.evaluate('a/b[.="foo"]')
end
it_behaves_like :node_set, :length => 1
example 'return the first <b> node' do
@set[0].should == @document.children[0].children[0]
end
end
end
end