CSV.parse can't read back what CSV.generate wrote when a quoted field contains \r
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 57/100
Hướng nghiên cứu
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.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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).
- Ngôn ngữ chính
- Ruby
- Star
- 221
- Fork
- 142
- Merge trung bình
- 1 ngày 1 giờ
- Pull request đã merge (30 ngày)
- 2
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của ruby/csv
-
Unknown converter name is silently accepted and later fails with "undefined method 'arity' for nil"Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 57/100
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 68/100
-
Timeout on WindowsCó thể làm lại được @kou đã nhận 416 ngày trước và không có pull request nào đang mở. Đang mở
-
FiberError/NoMemoryError error related to csv gem occurs when upgrading from ruby 3.1 to 3.3Đang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
-
Recipes not copied downstreamĐang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 25/100
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
open-feature/ruby-sdk-contrib#340 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
zold-io/wts.zold.io#651 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
good first issue help wanted
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 87/100
erkamyaman/rust-anything#788 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 74/100
TheOdinProject/curriculum#31579 ·
Maintainer thường phản hồi trong vòng 1 ngày