From 6ac3408a71b2374ecd857ea13eee126233aca5a9 Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Fri, 22 Aug 2014 10:58:36 +0200 Subject: [PATCH] Match all node types when using node() Previously this would only match element and text nodes. --- lib/oga/xpath/evaluator.rb | 4 +--- spec/oga/xpath/evaluator/type_tests/node_spec.rb | 12 ++++++++++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/oga/xpath/evaluator.rb b/lib/oga/xpath/evaluator.rb index 27c35e2..f763922 100644 --- a/lib/oga/xpath/evaluator.rb +++ b/lib/oga/xpath/evaluator.rb @@ -515,9 +515,7 @@ module Oga nodes = XML::NodeSet.new context.each do |node| - if node.is_a?(XML::Element) or node.is_a?(XML::Text) - nodes << node - end + nodes << node if node.is_a?(XML::Node) end return nodes diff --git a/spec/oga/xpath/evaluator/type_tests/node_spec.rb b/spec/oga/xpath/evaluator/type_tests/node_spec.rb index 180caaf..e721e31 100644 --- a/spec/oga/xpath/evaluator/type_tests/node_spec.rb +++ b/spec/oga/xpath/evaluator/type_tests/node_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' describe Oga::XPath::Evaluator do context 'node() tests' do before do - @document = parse('foo') + @document = parse('foo') @evaluator = described_class.new(@document) end @@ -24,11 +24,19 @@ describe Oga::XPath::Evaluator do @set = @evaluator.evaluate('a/node()') end - it_behaves_like :node_set, :length => 1 + it_behaves_like :node_set, :length => 3 example 'return the node' do @set[0].name.should == 'b' end + + example 'return the "foo" comment' do + @set[1].text.should == 'foo' + end + + example 'return the "bar" CDATA tag' do + @set[2].text.should == 'bar' + end end context 'matching text nodes' do