XPath: and/or/div/mod right after a predicate raise ParseException
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 82/100
Research direction
Start with Predicate in lib/rexml/parsers/xpathparser.rb and trace how it handles whitespace after a closing ], then check the operator parsing in OrExpr, AndExpr, and MultiplicativeExpr. Run the issue’s Ruby examples before and after the change; done means the and and div expressions return [true] and [2.0], while the existing symbol operator and parenthesized cases continue to work.
Written by the indexing model from the issue text.
Description
A word operator (and, or, div, mod) right after a predicate fails to parse:
require "rexml/document"
doc = REXML::Document.new("<r><v>6</v><v>2</v></r>")
REXML::XPath.match(doc, "//v[1] and true()")
# REXML::ParseException: Garbage component exists at the end: <and true()>: <//v[1] and true()>
REXML::XPath.match(doc, "/r/v[1] div 3")
# REXML::ParseException: Garbage component exists at the end: <div 3>: </r/v[1] div 3>
Expected [true] and [2.0] (libxml2 gives those). Symbol operators work (//v[1] * 3, //v[1] = 6), and so do (//v[1]) div 3 and //v div 3.
Cause: Predicate in lib/rexml/parsers/xpathparser.rb calls path.lstrip after each ], so it returns "and true()". OrExpr, AndExpr and MultiplicativeExpr then look for /^\s*( and )/, /^\s*( or )/ and /^\s*(\*| div | mod )\s*/, which need the space before the word, so they don't match.
Possible fix: in Predicate, only strip the whitespace when another [ follows, and otherwise return the path with its leading space.
- Dominant language
- Ruby
- Stars
- 181
- Forks
- 105
- PR merge metrics
- No merged PRs in 30d
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from ruby/rexml
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
Difficulty 3/5 1-2 days Newbie friendliness 55/100
-
XPath underscored function name is wrongly acceptedPossibly taken @sjh9714 claimed this 80 days ago. Open
Difficulty 3/5 1-2 days Newbie friendliness 55/100
-
Difficulty 3/5 1-2 days Newbie friendliness 55/100
-
Difficulty 4/5 3-5 days Newbie friendliness 48/100
Similar issues
-
bug f:request-creation professional
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
mysociety/alaveteli#9733 · 1 comment ·
Maintainers usually reply within 1 day
-
needs verification
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
Maintainers usually reply within 13 days
-
🐛 bug 👩💻 équipe CE 🧑🏭 entreprises
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
betagouv/conseillers-entreprises#4808 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day