CSV.parse can't read back what CSV.generate wrote when a quoted field contains \r
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 57/100
Direzione di ricerca
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.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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).
- Lingua principale
- Ruby
- Stelle
- 221
- Fork
- 142
- Merge medio
- 1g 1h
- PR unite (30g)
- 2
Preparare l'ambiente
Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di ruby/csv
-
Unknown converter name is silently accepted and later fails with "undefined method 'arity' for nil"Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 57/100
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 68/100
-
Timeout on WindowsForse di nuovo libera @kou l’ha presa 416 giorni fa e non c’è nessuna pull request aperta. Aperta
-
FiberError/NoMemoryError error related to csv gem occurs when upgrading from ruby 3.1 to 3.3Aperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 25/100
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
open-feature/ruby-sdk-contrib#340 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
zold-io/wts.zold.io#651 ·
I maintainer di solito rispondono entro 1 giorno
-
good first issue help wanted
Difficoltà 2/5 1-3 ore Idoneità per principianti 87/100
erkamyaman/rust-anything#788 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 74/100
TheOdinProject/curriculum#31579 ·
I maintainer di solito rispondono entro 1 giorno