From 7eea98fb3b32ea43190136d2e2b23911425a4faa Mon Sep 17 00:00:00 2001 From: Yun Zheng Hu Date: Fri, 18 Jul 2025 12:55:02 +0000 Subject: [PATCH] Suppress csv.Sniffer exception Sometimes Sniffer cannot determine the delimiter and would raise: Could not determine delimiter We now suppress this exception so it can still continue parsing the CSV with default settings. --- flow/record/adapter/csvfile.py | 4 +++- tests/test_regression.py | 10 ++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/flow/record/adapter/csvfile.py b/flow/record/adapter/csvfile.py index cba8442c..108b3955 100644 --- a/flow/record/adapter/csvfile.py +++ b/flow/record/adapter/csvfile.py @@ -1,5 +1,6 @@ from __future__ import annotations +import contextlib import csv import sys from pathlib import Path @@ -89,7 +90,8 @@ def __init__( self.dialect = "excel" if self.fp.seekable(): - self.dialect = csv.Sniffer().sniff(self.fp.read(1024)) + with contextlib.suppress(csv.Error): + self.dialect = csv.Sniffer().sniff(self.fp.read(1024)) self.fp.seek(0) self.reader = csv.reader(self.fp, dialect=self.dialect) diff --git a/tests/test_regression.py b/tests/test_regression.py index e39640b0..f4a9b509 100644 --- a/tests/test_regression.py +++ b/tests/test_regression.py @@ -711,5 +711,15 @@ def test_rdump_selected_fields(capsysbinary: pytest.CaptureFixture) -> None: assert captured.out == b"Q42eWSaF,A sample pastebin record,text\r\n" +def test_rdump_csv_sniff(tmp_path: Path, capsysbinary: pytest.CaptureFixture) -> None: + csv_path = tmp_path / "test.csv" + csv_path.write_text("ip,common_name,vulnerable\n127.0.0.1,localhost,1\n192.168.4.20,") + rdump.main([str(csv_path)]) + + captured = capsysbinary.readouterr() + assert b"" in captured.out + assert b"" in captured.out + + if __name__ == "__main__": __import__("standalone_test").main(globals())