Repository navigation
fix(bundles): accept a leading UTF-8 BOM in JSON readers - #5558
adityajai119 wants to merge 1 commit into
Conversation
Fixes github#5556. Assisted-by: OpenCode (model: Gemini 4 Neon, autonomous)
There was a problem hiding this comment.
🔵 Needs a closer look
Human review is warranted because the shared JSON parsing changes affect project records, integration markers, catalogs, HTTPS responses, and snapshots, with cross-platform and downstream CLI behavior not fully validated.
No open issues 🎉
What changed in this PR
This pull request updates bundler JSON parsing to accept a single leading UTF-8 BOM, enabling compatibility with Windows PowerShell 5.1-generated catalogs while preserving strict validation for malformed JSON, duplicate keys, and invalid BOM placement.
Changes:
- Routes
load_json()through the sharedloads_json()parser. - Strips exactly one leading U+FEFF before parsing JSON.
- Adds regression coverage across files, URLs, fetched catalogs, project metadata, edge cases, and PowerShell 5.1 workflows.
| File | Description |
|---|---|
| tests/specify_cli/bundles/test_yamlio.py | Adds positive and negative BOM regression coverage across JSON readers, catalog fetchers, project metadata, and Windows PowerShell 5.1 workflows. |
| src/specify_cli/bundles/yamlio.py | Centralizes JSON parsing through loads_json() and accepts exactly one leading UTF-8 BOM while preserving existing validation behavior. |
Review effort: Lite (adaptive)
There was a problem hiding this comment.
🟡 Changes recommended
The CLI regression test reads the developer’s real catalog configuration, so a locally configured HTTPS catalog can cause an unrelated offline-search failure; isolate it with an empty temporary configuration directory.
1 open issue
Review effort: Balanced
|
|
||
| monkeypatch.chdir(project) | ||
| monkeypatch.delenv("SPECIFY_INIT_DIR", raising=False) | ||
| runner = CliRunner() |
|
Please address Copilot feedback |

Description
Fixes #5556.
Both bundler JSON readers in
src/specify_cli/bundles/yamlio.pyopened JSON asplain
utf-8.json.load()/json.loads()reject a leading U+FEFF withUnexpected UTF-8 BOM (decode using utf-8-sig), so a single BOM breaks everybundler JSON path:
load_json()—.specify/bundle-records.jsonand.specify/integration.jsonloads_json()— catalog payloads from plain paths,file://URLs, HTTPSfetches, and packaged snapshots
specify bundle catalog addandspecify bundle searchWindows PowerShell 5.1's
ConvertTo-Json -Encoding UTF8writes that BOM, so acatalog authored with the documented Windows tooling could not be added or
searched.
Fix
Strip one leading U+FEFF in
loads_json(), the shared parse boundary, and routeload_json()through it. The BOM is removed only at position zero: a doubledBOM, a non-leading BOM, malformed JSON, and duplicate keys still produce a
BundlerError. A literal U+FEFF inside a string is preserved.Testing
Red -> Green regression evidence (
tests/specify_cli/bundles/test_yamlio.py)maine59953d): 6 failed, 9 passed —load_json,loads_json, bundle records, local/HTTPS catalog fetchers, and thePowerShell 5.1 end-to-end CLI test all failed on the BOM.
Added positive coverage (BOM + unicode, across local path,
file://, HTTPS,records, integration marker, and a real Windows PowerShell 5.1 generated
catalog driven through
bundle catalog add/bundle search) and negativecoverage (doubled BOM, non-leading BOM, BOM-only input, malformed JSON after
BOM, duplicate key after BOM).
Verification commands
.\.venv\Scripts\python.exe -m pytest tests/specify_cli/bundles/test_yamlio.py -q→ 15 passed.\.venv\Scripts\python.exe -m pytest tests/specify_cli/bundles -q→ 1321 passed, 4 skippeduvx ruff@0.15.0 check src tests→ All checks passed!.\.venv\Scripts\python.exe .github/scripts/check_extension_version_bump.py origin/main HEAD→ all invariants hold.\.venv\Scripts\python.exe .github/scripts/check_file_helper_migration.py --base origin/main --head HEAD→ exit 0.\.venv\Scripts\specify.exe --help→ exit 0git diff --check→ cleanTested locally with
.\.venv\Scripts\specify.exe --helpRan relevant existing tests with
.\.venv\Scripts\python.exe -m pytestTested with a sample project (PowerShell 5.1 BOM catalog end-to-end)
AI Disclosure
AI disclosure: Implemented and verified with OpenCode (model: Gemini 4 Neon,
autonomous mode); root-cause investigation, regression tests, code fix, issue
report, and verification runs were authored and executed autonomously on behalf
of
adityajai119.