XPath "self" axis inside predicates.
The "self" axis should use the current context node when inside a predicate.
This commit is contained in:
parent
71f2b42074
commit
2b96d65103
|
@ -490,9 +490,13 @@ module Oga
|
|||
def on_axis_self(ast_node, context)
|
||||
nodes = XML::NodeSet.new
|
||||
|
||||
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
|
||||
end
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue