diff --git a/lib/oga/xpath/compiler.rb b/lib/oga/xpath/compiler.rb index 32f6937..64e24df 100644 --- a/lib/oga/xpath/compiler.rb +++ b/lib/oga/xpath/compiler.rb @@ -176,7 +176,7 @@ module Oga def on_axis_ancestor_or_self(ast, input) parent = unique_literal(:parent) - process(ast, input) + process(ast, input).and(input.is_a?(XML::Node)) .if_true { yield input } .followed_by do attribute_or_node(input).if_true do diff --git a/spec/oga/xpath/compiler/axes/ancestor_or_self_spec.rb b/spec/oga/xpath/compiler/axes/ancestor_or_self_spec.rb index 8c1b55a..9caa061 100644 --- a/spec/oga/xpath/compiler/axes/ancestor_or_self_spec.rb +++ b/spec/oga/xpath/compiler/axes/ancestor_or_self_spec.rb @@ -23,6 +23,12 @@ describe Oga::XPath::Compiler do evaluate_xpath(@a1.attribute('foo')).should == node_set(@a1) end end + + describe 'ancestor-or-self::foo' do + it 'returns an empty NodeSet' do + evaluate_xpath(@a1.attribute('foo')).should == node_set + end + end end describe 'relative to an element' do