mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-07-23 09:24:31 +02:00
Merge e1d0fba30f into a947dc6739
This commit is contained in:
commit
5b6bddeb9d
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))]
|
||||
|
|
|
|||
|
|
@ -252,6 +252,23 @@ def test_insert_csv_empty_null(db_path, empty_null):
|
|||
]
|
||||
|
||||
|
||||
def test_insert_csv_nul_bytes(db_path, tmpdir):
|
||||
# Regression test for https://github.com/simonw/sqlite-utils/issues/582
|
||||
# CSV files containing NUL bytes should be imported without crashing.
|
||||
file_path = str(tmpdir / "nul.csv")
|
||||
with open(file_path, "wb") as fp:
|
||||
fp.write(b"id,name\n1,Al\x00ice\n2,Bob\n")
|
||||
result = CliRunner().invoke(
|
||||
cli.cli,
|
||||
["insert", db_path, "data", file_path, "--csv", "--no-detect-types"],
|
||||
catch_exceptions=False,
|
||||
)
|
||||
assert result.exit_code == 0
|
||||
db = Database(db_path)
|
||||
rows = list(db["data"].rows)
|
||||
assert rows == [{"id": "1", "name": "Alice"}, {"id": "2", "name": "Bob"}]
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"input,args",
|
||||
(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue