8000 Fix reverse sort in xpath_parser by tompng · Pull Request #251 · ruby/rexml · GitHub
[go: up one dir, main page]

Skip to content

Fix reverse sort in xpath_parser #251

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 3, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Fix reverse sort in xpath_parser
  • Loading branch information
tompng committed Apr 30, 2025
commit cb0c9d280da128463a65692e87ba24e3a6682d34
2 changes: 1 addition & 1 deletion lib/rexml/xpath_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@ def sort(array_of_nodes, order)
if order == :forward
index
else
-index
index.map(&:-@)
end
end
ordered.collect do |_index, node|
Expand Down
4 changes: 4 additions & 0 deletions test/xpath/test_base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,10 @@ def test_preceding
assert_equal("c", matches[0].name)
assert_equal("b", matches[1].name)

d = REXML::Document.new("<a><b/><c/><d/><d/></a>")
cs = REXML::XPath.match(d, "a/d/preceding::node()")
assert_equal(["d", "c", "c", "b", "b"], cs.map(&:name))

s = "<a><b><c id='1'/></b><b><b><c id='2'/><c id='3'/></b><c id='4'/></b><c id='NOMATCH'><c id='5'/></c></a>"
d = REXML::Document.new(s)
c = REXML::XPath.match( d, "//c[@id = '5']")
Expand Down
Loading
0