diff --git a/lib/oga/xpath/evaluator.rb b/lib/oga/xpath/evaluator.rb index 6065c54..b0402ce 100644 --- a/lib/oga/xpath/evaluator.rb +++ b/lib/oga/xpath/evaluator.rb @@ -550,7 +550,9 @@ module Oga nodes = XML::NodeSet.new context.each do |node| - nodes << node if node.is_a?(XML::Node) + if node.is_a?(XML::Node) or node.is_a?(XML::Document) + nodes << node + end end return nodes diff --git a/spec/oga/xpath/evaluator/axes/self_spec.rb b/spec/oga/xpath/evaluator/axes/self_spec.rb index b499ce9..85eb0e8 100644 --- a/spec/oga/xpath/evaluator/axes/self_spec.rb +++ b/spec/oga/xpath/evaluator/axes/self_spec.rb @@ -74,5 +74,17 @@ describe Oga::XPath::Evaluator do @set[0].should == @document.children[0].children[1] end end + + context 'matching the document itself' do + before do + @set = @evaluator.evaluate('self::node()') + end + + it_behaves_like :node_set, :length => 1 + + example 'return the document itself' do + @set[0].is_a?(Oga::XML::Document).should == true + end + end end end