Repository navigation
hashdict: --lookup reads a dictionary JSON saved with a UTF-8 BOM - #5768
evilclanker9000 wants to merge 1 commit into
Conversation
…5.1-saved JSON works
|
Tested
AI-assisted. |
|
Verified at your head on main 561b65a: test_hashdict 36/36 including the new BOM case (verified by name), test_tool_stdout_encoding unaffected. The convention is real — world_build.py:117 and world_names.py:244 already read utf-8-sig — and for BOM-less input utf-8-sig decodes byte-identically, so there is no behavioral change for existing dictionaries and no way this widens any report output. Writer stays pinned. Checks pending. AI-assisted: yes. Tested on Linux (RTX 5080 host, CPU-only run). |
|
Tested 533658d merged with main 561b65a on Linux (WSL2) / Python 3.12.16 and on Windows (native) / Python 3.13.1: pass
Negative control: with |
What and why
tools/hashdict.py --lookup <hashes.json>opened the dictionary withencoding="utf-8", so a dictionary saved with a UTF-8 BOM failed withERROR: cannot read the dictionary ...: Unexpected UTF-8 BOM (decode using utf-8-sig)and exit 2. Windows PowerShell 5.1 writes exactly that BOM (Set-Content,Out-File), and the other JSON readers in the repo already accept it:tools/world_build.py,tools/world_names.pyandtools/opus_tags.pyopen withutf-8-sig,tests/test_boot_trace.pyhastest_utf8_bom_is_stripped, and #4591 goes the same way for word lists.The read is now
encoding="utf-8-sig"(no behavior change for a BOM-less file, whichutf-8-sigalso decodes). Item: EGEN-HASHDICT-BOM-DICT.Test
python -I tests/test_hashdict.py(newLookupCLITest.test_lookup_reads_a_dictionary_saved_with_a_utf8_bom, which writes the dictionary asb"\xef\xbb\xbf" + json.dumps(...)).Without the change (test added, tool unchanged):
With the change:
GPU and driver: none needed. No game data: the test dictionary is three made-up hash/name pairs.
Notes
The same file has other open PRs (#4565, #4675, #5528); this one touches only the
--lookupread, so it does not overlap their hunks. I left the per-archiveindex.jsonread alone:rpf9_carve.pywrites that file without a BOM, so there is no user-facing case to fix there.AI-assisted.