From 90cc878c444b19d91541963ab493d8d990c645b9 Mon Sep 17 00:00:00 2001 From: tompng Date: Wed, 17 Jun 2026 11:49:46 +0900 Subject: [PATCH] Fix XPath self axis nodeset order Self axis shuld create nodesets that each node have position=1 --- lib/rexml/xpath_parser.rb | 2 +- test/xpath/test_base.rb | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/rexml/xpath_parser.rb b/lib/rexml/xpath_parser.rb index 821cca95..279ba05a 100644 --- a/lib/rexml/xpath_parser.rb +++ b/lib/rexml/xpath_parser.rb @@ -199,7 +199,7 @@ def expr( path_stack, nodeset, context=nil ) nodeset = [nodeset.first.root_node] when :self nodeset = step(path_stack) do - [:iterate_nodesets, [nodeset]] + [:iterate_nodesets, nodeset.map {|node| [node] }] end when :child nodeset = step(path_stack) do diff --git a/test/xpath/test_base.rb b/test/xpath/test_base.rb index 43fe3e99..4d464869 100644 --- a/test/xpath/test_base.rb +++ b/test/xpath/test_base.rb @@ -276,6 +276,12 @@ def test_axe_self assert_equal "c", XPath::first( c, "self::node()" ).name end + def test_axe_self_order + doc = REXML::Document.new "" + assert_equal(["b", "c", "d"], XPath.match(doc, "a/*/self::*[1]").map(&:name)) + assert_equal([], XPath.match(doc, "a/*/self::*[2]").map(&:name)) + end + def test_axe_ancestor doc = REXML::Document.new "