Fixed descendant-or-self with a predicate.
Processing of this axis along with a predicate wouldn't quite work out. Even if the predicate returned false the node would still be matched (which should not be the case).
This commit is contained in:
parent
47e4a3aa49
commit
b304b8b077
|
@ -319,12 +319,8 @@ module Oga
|
|||
nodes = XML::NodeSet.new
|
||||
|
||||
context.each do |context_node|
|
||||
context_node.children.each do |node|
|
||||
nodes << node if node_matches?(node, ast_node)
|
||||
end
|
||||
|
||||
context_node.each_node do |node|
|
||||
nodes << node if node_matches?(node, ast_node)
|
||||
nodes.concat(process(ast_node, XML::NodeSet.new([node])))
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ require 'spec_helper'
|
|||
describe Oga::XPath::Evaluator do
|
||||
context 'descendant-or-self axis' do
|
||||
before do
|
||||
document = parse('<a><b><b><c></c></b></b></a>')
|
||||
document = parse('<a><b><b><c class="x"></c></b></b></a>')
|
||||
|
||||
@first_a = document.children[0]
|
||||
@first_b = @first_a.children[0]
|
||||
|
@ -40,6 +40,14 @@ describe Oga::XPath::Evaluator do
|
|||
end
|
||||
end
|
||||
|
||||
context 'nested descendants with a matching predicate' do
|
||||
before do
|
||||
@set = @evaluator.evaluate('descendant-or-self::c[@class="x"]')
|
||||
end
|
||||
|
||||
it_behaves_like :node_set, :length => 1
|
||||
end
|
||||
|
||||
context 'descendants of a specific node' do
|
||||
before do
|
||||
@set = @evaluator.evaluate('a/descendant-or-self::b')
|
||||
|
@ -88,6 +96,22 @@ describe Oga::XPath::Evaluator do
|
|||
it_behaves_like :empty_node_set
|
||||
end
|
||||
|
||||
context 'direct descendants without a matching predicate' do
|
||||
before do
|
||||
@set = @evaluator.evaluate('descendant-or-self::a[@class]')
|
||||
end
|
||||
|
||||
it_behaves_like :empty_node_set
|
||||
end
|
||||
|
||||
context 'nested descendants without a matching predicate' do
|
||||
before do
|
||||
@set = @evaluator.evaluate('descendant-or-self::b[@class]')
|
||||
end
|
||||
|
||||
it_behaves_like :empty_node_set
|
||||
end
|
||||
|
||||
context 'direct descendants using the short form' do
|
||||
before do
|
||||
@set = @evaluator.evaluate('//b')
|
||||
|
|
Loading…
Reference in New Issue