mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-07-23 09:24:31 +02:00
Strip NUL bytes from CSV input to prevent crash
When a CSV file contains NUL bytes the csv module raises _csv.Error: line contains NUL, crashing the insert command without a useful error message. Stripping \x00 from each line before passing it to the reader preserves all meaningful data while matching the behaviour users expect. Fixes #582.
This commit is contained in:
parent
a947dc6739
commit
e1d0fba30f
2 changed files with 21 additions and 1 deletions
|
|
@ -1237,7 +1237,10 @@ def insert_upsert_implementation(
|
|||
csv_reader_args["delimiter"] = delimiter
|
||||
if quotechar:
|
||||
csv_reader_args["quotechar"] = quotechar
|
||||
reader = csv_std.reader(decoded, **csv_reader_args) # type: ignore
|
||||
reader = csv_std.reader( # type: ignore
|
||||
(line.replace("\x00", "") for line in decoded),
|
||||
**csv_reader_args,
|
||||
)
|
||||
first_row = next(reader)
|
||||
if no_headers:
|
||||
headers = ["untitled_{}".format(i + 1) for i in range(len(first_row))]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue