From 6eacf74da4a3ecec015677b5b6cc18fd7324a4d5 Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Mon, 1 Sep 2014 22:34:18 +0200 Subject: [PATCH] Fixed comparing node equality in XPath expressions Previously this would take the text of the entire node set, not of the first node in the set. --- lib/oga/xpath/evaluator.rb | 4 ++-- spec/oga/xpath/evaluator/operators/eq_spec.rb | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/oga/xpath/evaluator.rb b/lib/oga/xpath/evaluator.rb index 48f265a..2627603 100644 --- a/lib/oga/xpath/evaluator.rb +++ b/lib/oga/xpath/evaluator.rb @@ -724,11 +724,11 @@ module Oga right = process(ast_node.children[1], context) if left.is_a?(XML::NodeSet) - left = left.text + left = first_node_text(left) end if right.is_a?(XML::NodeSet) - right = right.text + right = first_node_text(right) end if left.is_a?(Numeric) and !right.is_a?(Numeric) diff --git a/spec/oga/xpath/evaluator/operators/eq_spec.rb b/spec/oga/xpath/evaluator/operators/eq_spec.rb index 9d46f1d..b0411c3 100644 --- a/spec/oga/xpath/evaluator/operators/eq_spec.rb +++ b/spec/oga/xpath/evaluator/operators/eq_spec.rb @@ -46,5 +46,13 @@ describe Oga::XPath::Evaluator do example 'return true if a node set and a string are equal' do @evaluator.evaluate('root/a = "10"').should == true end + + example 'return true if a node set wildcard and a number are equal' do + @evaluator.evaluate('root/* = 10').should == true + end + + example 'return true if a number and a node set wildcard are equal' do + @evaluator.evaluate('10 = root/*').should == true + end end end