@@ -156,7 +156,7 @@ def match(path_stack, node)
156156 result = expr ( path_stack , nodeset )
157157 case result
158158 when Array # nodeset
159- result . uniq
159+ XPathParser . sort ( result )
160160 else
161161 [ result ]
162162 end
@@ -199,7 +199,7 @@ def expr( path_stack, nodeset, context=nil )
199199 nodeset = [ nodeset . first . root_node ]
200200 when :self
201201 nodeset = step ( path_stack ) do
202- [ :iterate_nodesets , [ nodeset ] ]
202+ [ :iterate_nodesets , [ XPathParser . sort ( nodeset ) ] ]
203203 end
204204 when :child
205205 nodeset = step ( path_stack ) do
@@ -323,7 +323,7 @@ def expr( path_stack, nodeset, context=nil )
323323 # If result is a nodeset, apply following predicates
324324 path_stack . unshift ( :node )
325325 nodeset = step ( path_stack ) do
326- [ :iterate_nodesets , [ result ] ]
326+ [ :iterate_nodesets , [ XPathParser . sort ( result ) ] ]
327327 end
328328 else
329329 return result
@@ -571,6 +571,7 @@ def split_positional_predicates(predicates)
571571 end
572572
573573 # Performs an axis scanning step.
574+ # Returns an unordered non-duplicated nodeset of matching nodes.
574575 # The caller provides a scanner method and its argument, which determines the axis to scan and the nodes to scan from:
575576 # step(path_stack) { [scanner_method, scanner_argument] }
576577 # Scanner methods are called with `(scanner_argument, tester_block, selector)`
@@ -621,7 +622,7 @@ def step(path_stack, any_type: :element)
621622 nodes << node
622623 end
623624 end
624- new_nodeset = sort ( nodes . to_a )
625+ new_nodeset = nodes . to_a
625626 ensure
626627 leave ( :step , path_stack , new_nodeset ) if @debug
627628 end
@@ -761,7 +762,7 @@ def leave(tag, *args)
761762 # in and out of function calls. If I knew what the index of the nodes was,
762763 # I wouldn't have to do this. Maybe add a document IDX for each node?
763764 # Problems with mutable documents. Or, rewrite everything.
764- def sort ( array_of_nodes )
765+ def self . sort ( array_of_nodes )
765766 return array_of_nodes if array_of_nodes . size <= 1
766767
767768 new_arry = [ ]
0 commit comments