XPath: and/or/div/mod right after a predicate raise ParseException
還沒有人認領這個 Issue。
評估
研究方向
從 lib/rexml/parsers/xpathparser.rb 中的 Predicate 開始,追蹤它如何處理閉合 ] 後的空白,接著檢查 OrExpr、AndExpr 和 MultiplicativeExpr 中的運算子解析。在變更前後執行 issue 中的 Ruby 範例;當 and 和 div 運算式回傳 [true] 和 [2.0],且現有的符號運算子和括號案例仍能正常運作時,就算完成。
由索引模型根據 Issue 內容生成。
描述
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.
- 主要語言
- Ruby
- 星號
- 181
- 分支
- 105
- PR 合併指標
- 30 天內沒有已合併 PR
環境準備
這個專案沒有提供開發容器、Dockerfile 或貢獻指南,環境需要你自己搭建:先看它的 README,通用步驟見我們的新手貢獻指南。
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
ruby/rexml 的其他 Issue
-
難度 2/5 1-3 小時 新手友好度 78/100
-
難度 3/5 1-2 天 新手友好度 55/100
-
XPath underscored function name is wrongly accepted可能已有人在做 @sjh9714 於 80 天前認領。 未關閉
難度 3/5 1-2 天 新手友好度 55/100
-
難度 3/5 1-2 天 新手友好度 55/100
-
難度 4/5 3-5 天 新手友好度 48/100
相似的 Issue
-
Pro request form loses all text when the subject is too long可能已有人在做 關聯的 PR 仍在進行中或已合併。 未關閉bug f:request-creation professional
難度 2/5 1-3 小時 新手友好度 64/100
mysociety/alaveteli#9733 · 1 則留言 ·
維護者通常 1 天內回覆
-
needs verification
難度 2/5 1-3 小時 新手友好度 64/100
維護者通常 13 天內回覆
-
🐛 bug 👩💻 équipe CE 🧑🏭 entreprises
難度 2/5 1-3 小時 新手友好度 76/100
betagouv/conseillers-entreprises#4808 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 76/100
-
難度 2/5 1-3 小時 新手友好度 78/100
維護者通常 1 天內回覆