Skip node matching for incompatible nodes.
This commit is contained in:
parent
713d8a092b
commit
1f9d2ede95
|
@ -107,7 +107,9 @@ module Oga
|
||||||
nodes = XML::NodeSet.new
|
nodes = XML::NodeSet.new
|
||||||
|
|
||||||
context.each do |xml_node|
|
context.each do |xml_node|
|
||||||
nodes << xml_node if node_matches?(xml_node, node)
|
if can_match_node?(xml_node) and node_matches?(xml_node, node)
|
||||||
|
nodes << xml_node
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return nodes
|
return nodes
|
||||||
|
@ -259,6 +261,16 @@ module Oga
|
||||||
return name_matches && ns_matches
|
return name_matches && ns_matches
|
||||||
end
|
end
|
||||||
|
|
||||||
|
##
|
||||||
|
# Returns `true` if the given XML node can be compared using
|
||||||
|
# {#node_matches?}.
|
||||||
|
#
|
||||||
|
# @param [Oga::XML::Node] node
|
||||||
|
#
|
||||||
|
def can_match_node?(node)
|
||||||
|
return node.respond_to?(:name) && node.respond_to?(:namespace)
|
||||||
|
end
|
||||||
|
|
||||||
##
|
##
|
||||||
# @param [Oga::XML::Node] node
|
# @param [Oga::XML::Node] node
|
||||||
# @return [TrueClass|FalseClass]
|
# @return [TrueClass|FalseClass]
|
||||||
|
|
|
@ -2,7 +2,7 @@ require 'spec_helper'
|
||||||
|
|
||||||
describe Oga::XPath::Evaluator do
|
describe Oga::XPath::Evaluator do
|
||||||
before do
|
before do
|
||||||
@document = parse('<a><b></b><b></b><ns1:c></ns1:c></a>')
|
@document = parse('<a>Foo<b></b><b></b><ns1:c></ns1:c></a>')
|
||||||
@evaluator = described_class.new(@document)
|
@evaluator = described_class.new(@document)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -56,8 +56,8 @@ describe Oga::XPath::Evaluator do
|
||||||
example 'return the correct nodes' do
|
example 'return the correct nodes' do
|
||||||
a = @document.children[0]
|
a = @document.children[0]
|
||||||
|
|
||||||
@set[0].should == a.children[0]
|
@set[0].should == a.children[1]
|
||||||
@set[1].should == a.children[1]
|
@set[1].should == a.children[2]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue