mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-11-02 16:37:43 +01:00
Preserve carriage returns in quoted CSV/TSV fields (#895)
When reading CSV or TSV files through rows_from_file() or the CLI insert command, io.TextIOWrapper defaulted to universal-newline mode (newline=None), causing carriage returns (\r\n or lone \r) embedded inside quoted fields to be silently translated to \n before csv.reader could process them. Setting newline='' in TextIOWrapper preserves carriage returns in quoted fields according to the Python standard library csv module specification. Fixes #895
This commit is contained in:
parent
6bc1d33d58
commit
c27092220d
4 changed files with 49 additions and 3 deletions
|
|
@ -346,7 +346,7 @@ def rows_from_file(
|
|||
return (json.loads(line) for line in fp if line.strip()), Format.NL
|
||||
elif format == Format.CSV:
|
||||
use_encoding: str = encoding or "utf-8-sig"
|
||||
decoded_fp = io.TextIOWrapper(fp, encoding=use_encoding)
|
||||
decoded_fp = io.TextIOWrapper(fp, encoding=use_encoding, newline="")
|
||||
if dialect is not None:
|
||||
reader = csv.DictReader(decoded_fp, dialect=dialect)
|
||||
else:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue