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
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

View File

@ -3,7 +3,7 @@ require 'spec_helper'
describe Oga::XPath::Evaluator do
context 'node() tests' 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)
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 <b> 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