🛡️ Warracker is an open source, self-hostable warranty tracker to monitor expirations, store receipts, files. You own the data, your rules!
Fix #236: CSV import rejected valid headers (BOM/case/whitespace)
Omega (QA)65f184ced451
diff --git a/backend/warranties_routes.py b/backend/warranties_routes.pyindex e1d9819..935fa76 100644--- a/backend/warranties_routes.py+++ b/backend/warranties_routes.py@@ -1159,10 +1159,21 @@ def import_warranties():]try:- # Read the file content- stream = io.StringIO(file.stream.read().decode("UTF8"), newline=None)+ # Read the file content. utf-8-sig strips a BOM, which Excel and+ # other tools commonly prepend (issue #236: the first header then+ # reads as '\ufeffProductName' and fails validation).+ stream = io.StringIO(file.stream.read().decode("utf-8-sig"), newline=None)csv_reader = csv.DictReader(stream)+ # Normalize headers: strip whitespace/BOM remnants and match+ # case-insensitively against the documented header names.+ canonical = {h.lower(): h for h in REQUIRED_CSV_HEADERS + OPTIONAL_CSV_HEADERS}+ normalized_fieldnames = []+ for h in (csv_reader.fieldnames or []):+ key = (h or '').strip().lower()+ normalized_fieldnames.append(canonical.get(key, (h or '').strip()))+ csv_reader.fieldnames = normalized_fieldnames+# Validate headersheaders = csv_reader.fieldnames# Check required headers first