Fix parsing parenthesized xpath#322
Open
tompng wants to merge 2 commits into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds coverage and parser tweaks for XPath expressions involving parentheses, unions, and ambiguous * spacing, improving consistency when whitespace is present/absent.
Changes:
- Add XPath evaluation tests for parenthesized union expressions followed by
/and//. - Add XPathParser tests to ensure multiplication operator parsing is whitespace-insensitive.
- Adjust
PathExprparsing to handle parenthesized/filter expressions followed by location steps.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| test/xpath/test_base.rb | Adds evaluation tests for parenthesized XPath union expressions with subsequent path steps. |
| test/parser/test_xpath.rb | Adds parser-level tests for * operator behavior with/without spaces. |
| lib/rexml/parsers/xpathparser.rb | Updates PathExpr to better parse filter/parenthesized expressions followed by / or //. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+597
to
+605
| if /\A\s*\//.match?(rest) | ||
| rest = rest.lstrip | ||
| if rest[1] == ?/ | ||
| n << :descendant_or_self | ||
| n << :node | ||
| rest = rest[2..-1] | ||
| else | ||
| rest = rest[1..-1] | ||
| end |
Comment on lines
+115
to
+126
| def test_mult_and_spaces | ||
| parser = REXML::Parsers::XPathParser.new | ||
| assert_equal(parser.parse("1 * 2 * 3"), parser.parse("1*2*3")) | ||
| assert_equal(parser.parse("a[( ( 1 + 2 ) * 3 + 4 * ( 5 + 6 ) ) * 7 < 8]"), parser.parse("a[((1+2)*3+4*(5+6))*7<8]")) | ||
| # number(a/b) * 2 | ||
| assert_equal(parser.parse("(a/b) * 2"), parser.parse("(a/b)*2")) | ||
| assert_equal(parser.parse("a/b * 2"), parser.parse("a/b*2")) | ||
| # number(a/b/*) * 2 | ||
| assert_equal(parser.parse("a/b/* * 2"), parser.parse("a/b/**2")) | ||
| # number(*) * number(*/*) * number(*) | ||
| assert_equal(parser.parse("* * */* * *"), parser.parse("***/***")) | ||
| end |
c75c697 to
5b1e3e1
Compare
5b1e3e1 to
8031c92
Compare
Comment on lines
+593
to
602
| if /\A\s*\//.match?(rest) | ||
| rest = rest.lstrip | ||
| if rest.start_with?('//') | ||
| n << :descendant_or_self | ||
| n << :node | ||
| rest = rest[2..-1] | ||
| else # starts with '/' | ||
| rest = rest[1..-1] | ||
| end | ||
| rest = RelativeLocationPath(rest, n) |
Comment on lines
+590
to
+592
| if rest == path | ||
| rest = LocationPath(rest, n) | ||
| else |
| ) | ||
| end | ||
|
|
||
| def test_mult_asterisk_without_surrounding_spaces |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #316
Also fixes bug parsing
(1+2)*3Source code comment:
Actual implementation was:
With this pull request, the implementation will match to its source code comment.