BcpackHistory: accept a UTF-8 BOM in the history JSON #31

Manually merged
github merged 1 commit from gh-pr/31/head into gh-pr/31/base 2026-11-26 19:06:18 +00:00
Owner

@⁠throny on GitHub · 2026-11-23 18:25 UTC · original
bcpack-history-bom → main · +5 −1 · 1 files · 1 commits · merged 2026-11-23 22:30 UTC

BcpackHistory.Load fails on a history JSON that starts with a UTF-8 BOM (EF BB BF), which Windows PowerShell 5.1 Out-File/> writes by default: exit 2, '0xEF' is an invalid start of a value.

Cause: ReadDocument (from #22) passes the raw file bytes to JsonDocument.Parse, which does not accept a BOM.

Fix: skip the 3 BOM bytes before parsing. Every other error path is unchanged (bad JSON, non-object root, empty file).

Tested (no game files; no test project in the repo, so a scratch console app outside the repo calling BcpackHistory.Load):

  • plain JSON: OK; BOM + same JSON: fails before the fix, OK after
  • BOM-only file, BOM + [1], and malformed JSON: still InvalidDataException as before (BOM-only now reports "no JSON tokens", [1] "expected a JSON object")
  • dotnet build -c Release of Core, App and IndexBuilder: 0 warnings, 0 errors

AI-assisted. Came up in review of ItsNotRexed/Leonida#4050.

🤖 Generated with Claude Code

**@⁠throny** on GitHub · 2026-11-23 18:25 UTC · [original](https://github.com/breadbbbb/rpf9-explorer/pull/31) `bcpack-history-bom` → `main` · +5 −1 · 1 files · 1 commits · merged 2026-11-23 22:30 UTC `BcpackHistory.Load` fails on a history JSON that starts with a UTF-8 BOM (EF BB BF), which Windows PowerShell 5.1 `Out-File`/`>` writes by default: exit 2, `'0xEF' is an invalid start of a value`. **Cause:** `ReadDocument` (from #22) passes the raw file bytes to `JsonDocument.Parse`, which does not accept a BOM. **Fix:** skip the 3 BOM bytes before parsing. Every other error path is unchanged (bad JSON, non-object root, empty file). **Tested** (no game files; no test project in the repo, so a scratch console app outside the repo calling `BcpackHistory.Load`): - plain JSON: OK; BOM + same JSON: fails before the fix, OK after - BOM-only file, BOM + `[1]`, and malformed JSON: still `InvalidDataException` as before (BOM-only now reports "no JSON tokens", `[1]` "expected a JSON object") - `dotnet build -c Release` of Core, App and IndexBuilder: 0 warnings, 0 errors AI-assisted. Came up in review of ItsNotRexed/Leonida#4050. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
ReadDocument passed the raw bytes to JsonDocument, which rejects a leading
EF BB BF ('0xEF' is an invalid start of a value). Skip the BOM before parsing;
all other errors are unchanged.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 19:06:16 +00:00
github manually merged commit c6235a13f5 into gh-pr/31/base 2026-11-26 19:06:18 +00:00
Author
Owner

@⁠breadbbbb on GitHub · 2026-11-23 22:28 UTC · original · approved these changes

The Release core build passed. I called BcpackHistory.Load with the same BC1 object in plain UTF-8 and UTF-8 with a BOM. Both loaded. A BOM-only file, a BOM-prefixed array, and malformed JSON all still raised InvalidDataException.

**@⁠breadbbbb** on GitHub · 2026-11-23 22:28 UTC · [original](https://github.com/breadbbbb/rpf9-explorer/pull/31#pullrequestreview-6030534584) · **approved these changes** The Release core build passed. I called BcpackHistory.Load with the same BC1 object in plain UTF-8 and UTF-8 with a BOM. Both loaded. A BOM-only file, a BOM-prefixed array, and malformed JSON all still raised InvalidDataException.
This discussion has been locked. Commenting is limited to contributors.
No description provided.