diff --git a/lib/oga/xpath/evaluator.rb b/lib/oga/xpath/evaluator.rb index b9af481..a637a68 100644 --- a/lib/oga/xpath/evaluator.rb +++ b/lib/oga/xpath/evaluator.rb @@ -74,8 +74,8 @@ module Oga name_matches = xml_node.name == name || name == '*' ns_matches = false - if ns and (xml_node.namespace == ns or ns == '*') - ns_matches = true + if ns + ns_matches = xml_node.namespace == ns || ns == '*' # If there's no namespace given but the name matches we'll also mark # the namespace as matching. diff --git a/spec/oga/xpath/evaluator/wildcard_spec.rb b/spec/oga/xpath/evaluator/wildcard_spec.rb index 9ad60cb..20c448c 100644 --- a/spec/oga/xpath/evaluator/wildcard_spec.rb +++ b/spec/oga/xpath/evaluator/wildcard_spec.rb @@ -28,4 +28,41 @@ describe Oga::XPath::Evaluator do @set[2].namespace.should == 'ns1' end end + + context 'namespace wildcards' do + before do + @set = @evaluator.evaluate('a/*:b') + end + + example 'return the right amount of rows' do + @set.length.should == 2 + end + + example 'include the first node' do + @set[0].name.should == 'b' + end + + example 'include the second node' do + @set[1].name.should == 'b' + end + + example 'ensure the nodes are the individual nodes' do + @set[0].should_not == @set[1] + end + end + + context 'name wildcards' do + before do + @set = @evaluator.evaluate('a/ns1:*') + end + + example 'return the right amount of rows' do + @set.length.should == 1 + end + + example 'include the correct node' do + @set[0].name.should == 'c' + @set[0].namespace.should == 'ns1' + end + end end