Skip to content

fix(input): read triage files saved with a UTF-8 byte order mark - #6177

Merged
ffontaine merged 1 commit into
ossf:mainfrom
ranjithguggilla:fix/input-file-utf8-bom
Nov 29, 2026
Merged

ffontaine merged 1 commit into
ossf:mainfrom
ranjithguggilla:fix/input-file-utf8-bom

Conversation

@ranjithguggilla

Copy link
Copy Markdown
Contributor

--input-file refuses a triage CSV that was saved by Excel as "CSV UTF-8". Excel writes a UTF-8 byte order mark at the start, InputEngine.input_csv opens the file with the default encoding, and the first header comes out as vendor:

MissingFieldsError {'vendor'} are required fields

A JSON triage file with the same mark fails in json.load with Unexpected UTF-8 BOM.

This opens both files with encoding="utf-8-sig". Files without the mark are read the same as before, and the result no longer depends on the locale encoding.

The new test writes the existing test_triage.csv and test_triage.json fixtures with a byte order mark into tmp_path and checks they parse to the same data. It fails on main for both files and passes with the change. test/test_input_engine.py passes (11 tests) and the pre-commit hooks are clean.

One behaviour change to be aware of: on Windows the files used to be read with the locale encoding. A triage file saved in cp1252 with non-ASCII characters would now fail to decode, while UTF-8 files with non-ASCII text are no longer garbled.

Test plan

  • New test fails on main (MissingFieldsError for the CSV, Unexpected UTF-8 BOM for the JSON) and passes with the change
  • pytest test/test_input_engine.py — 11 passed
  • pre-commit on the two changed files, including gitlint
  • Windows (CI covers this; not run locally)

InputEngine opened --input-file CSV and JSON files with the platform
default encoding. A CSV saved by Excel as "CSV UTF-8", or a JSON file
written by a Windows editor, starts with a UTF-8 byte order mark, so
the first CSV header became "vendor" and the file was refused
with "{'vendor'} are required fields", and json.load raised
"Unexpected UTF-8 BOM".

Open both with encoding="utf-8-sig", which reads files with and
without the mark the same way and no longer depends on the locale.
@ffontaine

Copy link
Copy Markdown
Collaborator

All tests passed, merge time

@ffontaine
ffontaine merged commit d4df30e into ossf:main Nov 29, 2026
27 of 28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants