XPath: mod uses floored modulo instead of truncating remainder
還沒有人認領這個 Issue。
評估
研究方向
從 lib/rexml/xpath_parser.rb 中的 mod 運算開始,issue 指出 left % right 會造成符號不一致。閱讀周邊對除數為零以及運算元為無限大或 NaN 的處理,接著檢查是否有涵蓋負運算元和零的 XPath 測試。完成的標準是:範例符合 XPath 1.0 餘數的符號規則,同時 x mod 0 和指定的特殊情況仍回傳 NaN。
由索引模型根據 Issue 內容生成。
描述
XPath mod gives the wrong sign when an operand is negative:
require "rexml/document"
doc = REXML::Document.new("<r/>")
REXML::XPath.first(doc, "5 mod -2") # => -1.0, expected 1
REXML::XPath.first(doc, "-5 mod 2") # => 1.0, expected -1
REXML::XPath.first(doc, "-0.5 mod 3") # => 2.5, expected -0.5
The first two are the examples in the spec (https://www.w3.org/TR/xpath-10/#numbers):
The mod operator returns the remainder from a truncating division. For example,
5 mod 2 returns 1
5 mod -2 returns 1
-5 mod 2 returns -1
-5 mod -2 returns -1
libxml2 gives 1, -1 and -0.5.
Cause: lib/rexml/xpath_parser.rb uses left % right. Ruby's % is a floored modulo (the result takes the sign of the right side). left.remainder(right) truncates like the spec asks; it raises ZeroDivisionError for a zero right side, so x mod 0 (and an infinite or NaN left side) needs to keep returning NaN.
- 主要語言
- Ruby
- 星號
- 181
- 分支
- 105
- PR 合併指標
- 30 天內沒有已合併 PR
環境準備
這個專案沒有提供開發容器、Dockerfile 或貢獻指南,環境需要你自己搭建:先看它的 README,通用步驟見我們的新手貢獻指南。
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
ruby/rexml 的其他 Issue
-
難度 2/5 1-3 小時 新手友好度 82/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 天內回覆