Repository navigation
hashdict: read a carve index.json saved with a UTF-8 BOM (EGEN-HASHDICT-INDEX-BOM) - #6871
Conversation
…BOM is not a JSON error PowerShell 5.1 (Set-Content, Out-File) and old Notepad save JSON with a UTF-8 BOM; a BOM-prefixed index.json ended the whole dictionary build with 'Unexpected UTF-8 BOM (decode using utf-8-sig)' and exit 2. The other JSON readers in tools/ already accept utf-8-sig.
Writes common/index.json with a UTF-8 BOM and asserts the build exits 0 and keeps common_archive_asset. Without the utf-8-sig read it fails with exit 2 and 'Unexpected UTF-8 BOM'.
|
Verified at 5aa014d merged with current main 023952c: test_hashdict runs Ran 36 OK, and against main's unfixed tool the new test fails with exactly "Unexpected UTF-8 BOM" — main's #6929 fixed the same class in shader_stage_manifest but tools/hashdict.py still reads plain utf-8 (grep confirms), so this closes a real remaining gap. utf-8-sig matches the pattern the other tools/ readers already use. Checks pending. AI-assisted: yes. Tested on Linux (RTX 5080 host, CPU-only run). |
shayderrr
left a comment
There was a problem hiding this comment.
Summary
tools/hashdict.py::main now opens each carve index.json with utf-8-sig, matching the other JSON readers in tools/, and the docstring notes BOM-prefixed indexes are accepted. test_archive_index_saved_with_a_utf8_bom_is_read prepends the BOM bytes and asserts the archive asset still lands in the dictionary.
Why merge
Stops a PowerShell/Notepad-saved carve index from aborting the whole dictionary build with exit 2. One-line input fix with a regression test.
Verdict: Approve
|
Summary Why merge Verdict: Approve |
hashdict reads every carve archive's index as plain UTF-8:
A carve
index.jsonthat has passed through PowerShell 5.1 (Set-Content,Out-File) or old Notepad carries aUTF-8 BOM, and that read ends the whole dictionary build:
exit 2, no dictionary written — and the run has already harvested nothing, so the warning comes after all the other
archives were scanned. The other JSON readers in
tools/(root_spill_census,user_sgpr_census,tex_headers,text_tables) already open withutf-8-sigfor exactly this reason; this is the leftover one in the same file family.Changed:
tools/hashdict.py: open the archive index withutf-8-sig(one line, with the reason on the line above).tools/hashdict.pydocstring: says a BOM-prefixed index is accepted, next to the existing output-guard sentence.tests/test_hashdict.py:CarveAndExtraCLITest.test_archive_index_saved_with_a_utf8_bom_is_readprependsb"\xef\xbb\xbf"to the fixture'scommon/index.jsonand asserts exit 0 and thatcommon_archive_assetisstill in the dictionary.
Test
Before (at upstream/main
1cc6e3c12plus the test only):After (this branch):
No GPU needed; the fixture is built by hand in the test, no game files.
Notes
I took the index read rather than the
--lookupdictionary read because #5768 already covers--lookup, and keptthe change to the one read this branch does not touch, so the two can land in either order. A BOM is still not
accepted on
--extratext files: those go throughharvest()as bytes, where the three BOM bytes are not part ofany identifier run and are simply skipped — no change needed there.
AI-assisted.