Match all node types when using node()

Previously this would only match element and text nodes.
This commit is contained in:
Yorick Peterse 2014-08-22 10:58:36 +02:00
parent da09f1296c
commit 6ac3408a71
2 changed files with 11 additions and 5 deletions

View File

@ -515,9 +515,7 @@ module Oga
nodes = XML::NodeSet.new nodes = XML::NodeSet.new
context.each do |node| context.each do |node|
if node.is_a?(XML::Element) or node.is_a?(XML::Text) nodes << node if node.is_a?(XML::Node)
nodes << node
end
end end
return nodes return nodes

View File

@ -3,7 +3,7 @@ require 'spec_helper'
describe Oga::XPath::Evaluator do describe Oga::XPath::Evaluator do
context 'node() tests' do context 'node() tests' do
before do before do
@document = parse('<a><b>foo</b></a>') @document = parse('<a><b>foo</b><!--foo--><![CDATA[bar]]></a>')
@evaluator = described_class.new(@document) @evaluator = described_class.new(@document)
end end
@ -24,11 +24,19 @@ describe Oga::XPath::Evaluator do
@set = @evaluator.evaluate('a/node()') @set = @evaluator.evaluate('a/node()')
end end
it_behaves_like :node_set, :length => 1 it_behaves_like :node_set, :length => 3
example 'return the <b> node' do example 'return the <b> node' do
@set[0].name.should == 'b' @set[0].name.should == 'b'
end 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 end
context 'matching text nodes' do context 'matching text nodes' do