diff --git a/lib/oga/xpath/evaluator.rb b/lib/oga/xpath/evaluator.rb index 11e6ec2..5d4be27 100644 --- a/lib/oga/xpath/evaluator.rb +++ b/lib/oga/xpath/evaluator.rb @@ -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 diff --git a/spec/oga/xpath/evaluator/axes/self_spec.rb b/spec/oga/xpath/evaluator/axes/self_spec.rb index 346bb4e..c6a7444 100644 --- a/spec/oga/xpath/evaluator/axes/self_spec.rb +++ b/spec/oga/xpath/evaluator/axes/self_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' describe Oga::XPath::Evaluator do context 'self axis' do before do - @document = parse('') + @document = parse('foobar') @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 node' do + @set[0].should == @document.children[0].children[0] + end + end end end