Skip to content

fix(bundles): accept a leading UTF-8 BOM in JSON readers - #5558

Closed
adityajai119 wants to merge 1 commit into
github:mainfrom
adityajai119:fix/5556-json-utf8-bom
Closed

adityajai119 wants to merge 1 commit into
github:mainfrom
adityajai119:fix/5556-json-utf8-bom

Conversation

@adityajai119

Copy link
Copy Markdown
Contributor

Description

Fixes #5556.

Both bundler JSON readers in src/specify_cli/bundles/yamlio.py opened JSON as
plain utf-8. json.load() / json.loads() reject a leading U+FEFF with
Unexpected UTF-8 BOM (decode using utf-8-sig), so a single BOM breaks every
bundler JSON path:

  • load_json() — .specify/bundle-records.json and .specify/integration.json
  • loads_json() — catalog payloads from plain paths, file:// URLs, HTTPS
    fetches, and packaged snapshots
  • consequently specify bundle catalog add and specify bundle search

Windows PowerShell 5.1's ConvertTo-Json -Encoding UTF8 writes that BOM, so a
catalog 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 route
load_json() through it. The BOM is removed only at position zero: a doubled
BOM, 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)

  • Before fix (main e59953d): 6 failed, 9 passed — load_json,
    loads_json, bundle records, local/HTTPS catalog fetchers, and the
    PowerShell 5.1 end-to-end CLI test all failed on the BOM.
  • After fix: 15 passed.

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 negative
coverage (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 skipped

  • uvx 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 0

  • git diff --check → clean

  • Tested locally with .\.venv\Scripts\specify.exe --help

  • Ran relevant existing tests with .\.venv\Scripts\python.exe -m pytest

  • Tested with a sample project (PowerShell 5.1 BOM catalog end-to-end)

AI Disclosure

  • I did not use AI assistance for this contribution
  • I did use AI assistance (fill in the disclosure below)

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.

Fixes github#5556.

Assisted-by: OpenCode (model: Gemini 4 Neon, autonomous)
@adityajai119
adityajai119 requested a review from mnriem as a code owner November 24, 2026 17:06
Copilot AI adaptive review requested due to automatic review settings November 24, 2026 17:06

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 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 shared loads_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)

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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()
@mnriem

mnriem commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator

Please address Copilot feedback

@mnriem mnriem added the triage-must-have Verdict: high-value, important work for Spec Kit — do first label Nov 25, 2026
@adityajai119

Copy link
Copy Markdown
Contributor Author

Closing as superseded by #5557 (merged, Fixes #5556).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

triage-must-have Verdict: high-value, important work for Spec Kit — do first

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: bundler JSON readers reject UTF-8 BOM from PowerShell 5.1 catalogs

3 participants