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

未關閉 適合新手
#384 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

評估

難度
2/5
預估耗時
1-3 小時
新手友好度
82/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
ruby
領域
backend

研究方向

從 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,通用步驟見我們的新手貢獻指南。

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

ruby/rexml 的其他 Issue

查看 ruby/rexml 的全部 Issue

相似的 Issue

更多 Ruby Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。