Skip to content

Preserve whitespace before word operators after XPath predicates - #387

Open
FFspiky wants to merge 2 commits into
ruby:masterfrom
FFspiky:fix/xpath-predicate-word-operators
Open

FFspiky wants to merge 2 commits into
ruby:masterfrom
FFspiky:fix/xpath-predicate-word-operators

Conversation

@FFspiky

@FFspiky FFspiky commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #384. When an XPath predicate is followed by a word operator such as div or and, the predicate parser strips the separating whitespace. A top-level query can raise a parse error. Inside another predicate, the query can select the wrong nodes.

Consume the whitespace only when it separates consecutive predicates. The outer expression parser then receives the separator before and, or, div, and mod.

The nine new examples produce eight parse errors and one wrong result on master. All pass with the change. On the initial revision, the normal and frozen-string test runs each completed 858 tests with the same five existing Ractor omissions, and the gem built successfully. In a separate 20-query comparison with libxml2, all 20 results matched after the fix, up from 10 before.

OpenAI Codex prepared the patch and ran these checks with Ruby 3.3.6 on macOS arm64.

After review, c459c40 groups all nine XPath assertions in one test method. On Ruby 4.0.7 the XPath file passed all 109 tests (453 assertions). The normal and frozen-string suites each passed all 850 tests (2,698 assertions, zero omissions).

@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 for fixing this regression!
The fix in lib/rexml/parsers/xpathparser.rb looks good to me.

I left one minor inline suggestion on test/xpath/test_base.rb to simplify the test method and match the style of the surrounding tests.

Comment thread test/xpath/test_base.rb Resolved

This branch has not been deployed

No deployments
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.

XPath: and/or/div/mod right after a predicate raise ParseException

2 participants