Repository navigation
fix(input): read triage files saved with a UTF-8 byte order mark - #6177
Merged
Merged
Conversation
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.
Collaborator
|
All tests passed, merge time |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
--input-filerefuses 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_csvopens the file with the default encoding, and the first header comes out asvendor:A JSON triage file with the same mark fails in
json.loadwithUnexpected 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.csvandtest_triage.jsonfixtures with a byte order mark intotmp_pathand checks they parse to the same data. It fails onmainfor both files and passes with the change.test/test_input_engine.pypasses (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
main(MissingFieldsErrorfor the CSV,Unexpected UTF-8 BOMfor the JSON) and passes with the changepytest test/test_input_engine.py— 11 passed