From 70bea2071c48e629e6cb794203e64fa8869bd4fe Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Thu, 27 Aug 2015 10:49:32 +0200 Subject: [PATCH] Fixed ancestor-or-self relative to attributes Per libxml behaviour this axis shouldn't match attributes when using "ancestor-or-self::*". --- lib/oga/xpath/compiler.rb | 2 +- spec/oga/xpath/compiler/axes/ancestor_or_self_spec.rb | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) 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