You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
CSV row splitting: a lone CR ends a row only in a file with quotes, and an LFCR header loses the first row #1891
Whether a lone CR ends a CSV row depends on whether the file contains a quote anywhere, and an LFCR line end after the header loses the first data row.
printf'a,b\r1,2\r3,4\r'> cr_noq.csv # CR line ends, no quotesprintf'a,b\r1,"2"\r3,4\r'> cr_q.csv # the same with one quoted cellprintf'a,b\n\r1,2\n\r3,4\n\r'> lfcr.csv # LFCR line ends
(.csv.read [I64 I64] "cr_noq.csv") ; 1 row: a [1] b [2] -- "3,4" is lost
(.csv.read [I64 I64] "cr_q.csv") ; 2 rows: a [1 3] b [2 4]
(.csv.read [I64 I64] "lfcr.csv") ; 2 rows: a [0Nl 3] b [0Nl 4] -- "1,2" is lost
The row splitter has two paths: without quotes it splits at LF only (absorbing a CR right after it), with quotes it ends a row at LF, CRLF or a lone CR. The cell scanner ends a cell at CR in both, so in a quote-free CR file everything after a row's first CR is never read. The header reader consumes CRLF but not LFCR, so after an LFCR header the first data row starts at the CR and reads as empty.
What the reader should do
A row ends at LF, CRLF, a lone CR, or LFCR (one line end, as the data rows already treat it), the same with or without quotes, and the header ends the same way. The writer (.csv.write) emits LF line ends and quotes every cell holding a CR or LF, so its output reads the same under this rule (checked: a table with "x\ry" and "p\nq" cells round-trips through either path today); the change only affects files from elsewhere, where it recovers rows that are lost now.
Found while working on #1885 (strict mode refuses the quote-free CR case rather than losing the text).
Fixed in #1895: a row, and the header, ends at LF, CRLF, a lone CR or LFCR, with quotes in the file or without; inside a quoted cell they stay text. The quote-free scan now searches for LF and CR in one pass, so LF and CRLF files read as fast as before; .csv.write's output (LF line ends, CR/LF cells quoted) reads back cell for cell.
Activity
singaraiona commentedon Nov 28, 2026
Fixed in #1895: a row, and the header, ends at LF, CRLF, a lone CR or LFCR, with quotes in the file or without; inside a quoted cell they stay text. The quote-free scan now searches for LF and CR in one pass, so LF and CRLF files read as fast as before; .csv.write's output (LF line ends, CR/LF cells quoted) reads back cell for cell.
fix(csv): a row ends at LF, CRLF, a lone CR or LFCR, with quotes in t…
fix(csv): a row ends at LF, CRLF, a lone CR or LFCR, with quotes in t…
fix(csv): a row ends at LF, CRLF, a lone CR or LFCR, with quotes in t…
fix(csv): a row ends at LF, CRLF, a lone CR or LFCR, with quotes in t…
fix(csv): a row ends at LF, CRLF, a lone CR or LFCR, with quotes in t…