mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-07-27 03:14:33 +02:00
fix rows_from_file() crash on empty or whitespace-only input
When no format is specified, the auto-detect path calls csv.Sniffer().sniff()
on the first bytes of the file. For empty or whitespace-only files, strip()
produces an empty byte string, causing sniff("") to raise csv.Error.
Return an empty iterator early when first_bytes is empty.
This commit is contained in:
parent
a947dc6739
commit
1ddc3f0400
2 changed files with 9 additions and 0 deletions
|
|
@ -379,6 +379,8 @@ def rows_from_file(
|
|||
raise TypeError(
|
||||
"rows_from_file() requires a file-like object that supports peek(), such as io.BytesIO"
|
||||
)
|
||||
if not first_bytes:
|
||||
return iter([]), Format.CSV
|
||||
if first_bytes.startswith(b"[") or first_bytes.startswith(b"{"):
|
||||
# TODO: Detect newline-JSON
|
||||
return rows_from_file(buffered, format=Format.JSON)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue