CSV.parse can't read back what CSV.generate wrote when a quoted field contains \r
還沒有人認領這個 Issue。
評估
研究方向
Start by reading the row_sep documentation and tracing how row_sep: :auto detects separators when quoted fields contain \r; the report reproduces the issue with CSV.parse_line and CSV.parse. Check existing tests for automatic row separator detection and round-tripping generated CSV. Done means detection no longer misreads this generated input, or the documentation clearly explains the limitation.
由索引模型根據 Issue 內容生成。
描述
When a field contains a bare \r, CSV writes it quoted with the default "\n" row separator, but reading it back with the default row_sep: :auto either raises or silently merges rows:
require "csv"
CSV.parse_line(CSV.generate_line(["a\rb"]))
# => CSV::MalformedCSVError: Any value after quoted field isn't allowed in line 1.
csv = CSV.generate { |c| c << ["a\rb", "c"] << ["d", "e"] }
# => "\"a\rb\",c\nd,e\n"
CSV.parse(csv)
# => [["a\rb", "c\nd", "e\n"]] # two rows become one, with no error
CSV.parse(csv, row_sep: "\n")
# => [["a\rb", "c"], ["d", "e"]]
Auto-detection picks the first \r/\n it finds, which here is inside the quoted field, so "\r" is used as the row separator. I see this is documented in the row_sep docs ("The sequence will be selected even if it occurs in a quoted field, assuming that you would have the same line endings there"). But in this case the data was produced by CSV itself with default options, and the second example silently returns wrong rows rather than raising.
Would it make sense for auto-detection to skip over quoted fields, at least when the sample contains a quote character? If you'd rather keep the current behavior, a sentence in the row_sep docs about round-tripping data that contains \r would also help.
Checked with csv 3.3.8 (current main) and 3.3.5 (Ruby 3.3).
- 主要語言
- Ruby
- 星號
- 221
- 分支
- 142
- 平均合併
- 1 天 1 小時
- 30 天內合併 PR
- 2
環境準備
這個專案沒有提供開發容器、Dockerfile 或貢獻指南,環境需要你自己搭建:先看它的 README,通用步驟見我們的新手貢獻指南。
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
ruby/csv 的其他 Issue
-
Unknown converter name is silently accepted and later fails with "undefined method 'arity' for nil"未關閉
難度 2/5 1-3 小時 新手友好度 57/100
-
難度 3/5 1-2 天 新手友好度 68/100
-
Timeout on Windows可能重新可做 @kou 於 416 天前認領,目前沒有進行中的 PR。 未關閉
-
難度 4/5 3-5 天 新手友好度 35/100
-
難度 4/5 3-5 天 新手友好度 25/100
相似的 Issue
-
難度 2/5 1-3 小時 新手友好度 72/100
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 85/100
open-feature/ruby-sdk-contrib#340 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 88/100
zold-io/wts.zold.io#651 ·
維護者通常 1 天內回覆
-
good first issue help wanted
難度 2/5 1-3 小時 新手友好度 87/100
erkamyaman/rust-anything#788 ·
維護者通常 1 天內回覆
-
難度 1/5 1 小時以內 新手友好度 74/100
TheOdinProject/curriculum#31579 ·
維護者通常 1 天內回覆