diff --git a/lib/oga/xpath/evaluator.rb b/lib/oga/xpath/evaluator.rb index 26b77ab..0b77280 100644 --- a/lib/oga/xpath/evaluator.rb +++ b/lib/oga/xpath/evaluator.rb @@ -61,6 +61,8 @@ module Oga if test != last_node and !@stack.empty? swap_context + elsif @stack.empty? + break end end end diff --git a/spec/oga/xpath/evaluator/paths_spec.rb b/spec/oga/xpath/evaluator/paths_spec.rb index 6ca4ad7..b79024f 100644 --- a/spec/oga/xpath/evaluator/paths_spec.rb +++ b/spec/oga/xpath/evaluator/paths_spec.rb @@ -24,6 +24,16 @@ describe Oga::XPath::Evaluator do end end + context 'invalid absolute paths' do + before do + @set = @evaluator.evaluate('/x/a') + end + + example 'return an empty NodeSet' do + @set.empty?.should == true + end + end + context 'relative paths' do before do @set = @evaluator.evaluate('a') @@ -42,6 +52,16 @@ describe Oga::XPath::Evaluator do end end + context 'invalid relative paths' do + before do + @set = @evaluator.evaluate('x/a') + end + + example 'return an empty NodeSet' do + @set.empty?.should == true + end + end + context 'nested paths' do before do @set = @evaluator.evaluate('/a/b')