Skip to content

Fix XPath self axis nodeset position#336

Merged
naitoh merged 1 commit into
ruby:masterfrom
tompng:fix_self_axis
Jun 17, 2026
Merged

Fix XPath self axis nodeset position#336
naitoh merged 1 commit into
ruby:masterfrom
tompng:fix_self_axis

Conversation

@tompng

@tompng tompng commented Jun 17, 2026

Copy link
Copy Markdown
Member

Self axis should create nodesets that each node have position=1

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)

Self axis shuld create nodesets that each node have position=1
Copilot AI review requested due to automatic review settings June 17, 2026 03:04

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

This PR fixes XPath self axis predicate evaluation so positional predicates (e.g., [1], [2]) are applied per node rather than across the entire nodeset, and adds a regression test to validate the corrected behavior.

Changes:

  • Update :self axis evaluation to iterate over singleton nodesets per node, ensuring correct predicate context/positioning.
  • Add a test confirming self::*[1] matches each node’s own “self” and self::*[2] matches none in that pattern.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
test/xpath/test_base.rb Adds regression coverage for self axis positional predicate behavior.
lib/rexml/xpath_parser.rb Adjusts :self axis nodeset iteration to apply predicates with the correct per-node context.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@tompng tompng mentioned this pull request Jun 17, 2026
@tompng tompng changed the title Fix XPath self axis nodeset order Fix XPath self axis nodeset position Jun 17, 2026

@naitoh naitoh left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@naitoh naitoh merged commit 9640216 into ruby:master Jun 17, 2026
72 of 73 checks passed
@tompng tompng deleted the fix_self_axis branch June 17, 2026 14:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants