Skip to content

Commit 9640216

Browse files
authored
Fix XPath self axis nodeset position (#336)
Self axis should create nodesets that each node have position=1 ```ruby Nokogiri::XML('<a><b/><c/><d/></a>').xpath('a/*/self::*[1]').map(&:name) # => ["b", "c", "d"] REXML::XPath.match(REXML::Document.new('<a><b/><c/><d/></a>'),'a/*/self::*[1]') #=> [<b/>] (master, rexml-3.4.4) #=> [<b/>, <c/>, <d/>] (this PR) ```
1 parent a6aa43c commit 9640216

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

lib/rexml/xpath_parser.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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, nodeset.map {|node| [node] }]
203203
end
204204
when :child
205205
nodeset = step(path_stack) do

test/xpath/test_base.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,12 @@ def test_axe_self
276276
assert_equal "c", XPath::first( c, "self::node()" ).name
277277
end
278278

279+
def test_axe_self_order
280+
doc = REXML::Document.new "<a><b/><c/><d/></a>"
281+
assert_equal(["b", "c", "d"], XPath.match(doc, "a/*/self::*[1]").map(&:name))
282+
assert_equal([], XPath.match(doc, "a/*/self::*[2]").map(&:name))
283+
end
284+
279285
def test_axe_ancestor
280286
doc = REXML::Document.new "
281287
<a>

0 commit comments

Comments
 (0)