Skip to content

fix(server): theme files saved with a UTF-8 BOM are published instead of rejected - #32405

Merged
Yash-Singh1 merged 1 commit into
pingdotgg:mainfrom
felixlaga:fix/theme-file-utf8-bom
Nov 7, 2026
Merged

Yash-Singh1 merged 1 commit into
pingdotgg:mainfrom
felixlaga:fix/theme-file-utf8-bom

Conversation

@felixlaga

Copy link
Copy Markdown
Contributor

Problem

A theme JSON file that starts with a UTF-8 byte-order mark (BOM) is never published. The themes watcher skips it, and t3 theme set <file> rejects it as "not a valid theme file". Windows PowerShell 5 and editors set to "UTF-8 with BOM" write such files.

readThemeFileGuarded decodes the bytes with Buffer#toString("utf8"), which keeps the BOM, so JSON.parse fails. settings.json, keybindings.json and t3.json load the same bytes fine, because FileSystem.readFileString uses TextDecoder, which drops the BOM.

Change

The theme reader now decodes with TextDecoder too.

Scope and approval

This is a one-line fix for an obvious bug, and it makes theme files behave like the server's other JSON files. I searched issues and PRs for "theme BOM", "readThemeFileGuarded", "environmentTheme", "theme file byte order mark" and "theme json BOM" and found nothing related.

Verification

  • New file notepad.json (a theme prefixed with \uFEFF) in the existing case skips invalid files while keeping valid ones in apps/server/src/environmentTheme.test.ts.
  • vp test run apps/server/src/environmentTheme.test.ts with the fix: 5 passed.
  • With only environmentTheme.ts reverted to main: AssertionError: expected [ 'nightfall' ] to deeply equal [ 'nightfall', 'notepad' ].
  • apps/server/src/cli/theme.test.ts passes. vp run check:changed passes.
  • Runtime, with a temporary --base-dir and a theme file starting ef bb bf 7b: on main, node apps/server/src/bin.ts theme set nightfall.json fails with SchemaError(Expected a valid JSON string). With the fix it prints Published … as "nightfall" and set it as the environment theme.

Not checked: Windows itself, with files saved by real Windows editors.

Written by Claude Opus 5.5 (claude-opus-5-5) in the Claude Code harness, run from T3 Code.

🤖 Generated with Claude Code

… of rejected

A theme JSON file that starts with a UTF-8 byte-order mark is skipped by the themes
watcher and refused by `t3 theme set <file>` as "not a valid theme file". The guarded
theme reader decoded bytes with Buffer#toString, which keeps the BOM, so JSON.parse
failed. settings.json, keybindings.json and t3.json read through FileSystem.readFileString,
whose TextDecoder drops the BOM, so the same JSON loads there.

The theme reader now decodes with TextDecoder too.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added vouch:unvouched Author is not yet trusted in the VOUCHED list. size:XS 0-9 changed lines (additions + deletions). labels Nov 7, 2026
@macroscopeapp

ghost commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Approved at 79a5962

Macroscope's review found this PR approvable — Theme files with a UTF-8 BOM can now load through both the watcher and CLI. Existing validation and file safeguards remain intact, and product defaults are unchanged.

You can add or adjust custom eligibility rules. Learn more.

@coderabbitai

ghost commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Theme file decoding now uses TextDecoder instead of Buffer.toString("utf8"). The test covers a valid theme file with a UTF-8 BOM and expects it to be returned.

Changes: Theme file decoding

Layer / File(s) Summary
Decode and validate theme files
apps/server/src/environmentTheme.ts, apps/server/src/environmentTheme.test.ts
readThemeFileGuarded decodes theme file bytes with TextDecoder. The test adds a valid BOM-prefixed theme and expects both nightfall and notepad in the results.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: juliusmarminge

Merge Risk: Minimal · up to 79a59

Theme files with a UTF-8 BOM can now load. No merge-blocking issue was identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title clearly describes the fix for theme files with a UTF-8 BOM.
Description check Passed The description covers the problem, change, scope, and verification. It identifies the untested Windows environment and the agent used.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 83a3674 and 79a5962.

Files selected for processing: 2

  • apps/server/src/environmentTheme.test.ts
  • apps/server/src/environmentTheme.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 4 remain after this review.

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

Labels

size:XS 0-9 changed lines (additions + deletions). vouch:unvouched Author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants