Skip to content

Commit 79a5962

Browse files
felixlagaclaude
andcommitted
fix(server): theme files saved with a UTF-8 BOM are published instead 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]>
1 parent 0f4a130 commit 79a5962

2 files changed

Lines changed: 4 additions & 2 deletions

File tree

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ it.layer(NodeServices.layer)("environment theme", (it) => {
125125
withEnvironmentThemes(
126126
{
127127
"nightfall.json": encodeThemeFile(NIGHTFALL_THEME),
128+
"notepad.json": `\uFEFF${encodeThemeFile(SHARED_THEME)}`,
128129
"unresolved.json":
129130
'{ "name": "X", "appearance": "dark", "canvas": "{{ background }}", "accent": "#7aa2f7" }',
130131
"malformed.json": "{ not json",
@@ -137,7 +138,7 @@ it.layer(NodeServices.layer)("environment theme", (it) => {
137138
Effect.gen(function* () {
138139
assert.deepEqual(
139140
(yield* currentThemes).map((theme) => theme.id),
140-
["nightfall"],
141+
["nightfall", "notepad"],
141142
);
142143
}),
143144
),

‎apps/server/src/environmentTheme.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ export const readThemeFileGuarded = (filePath: string, maxBytes: number): string
8080
if (read <= 0) break;
8181
offset += read;
8282
}
83-
return contents.subarray(0, offset).toString("utf8");
83+
// Unlike Buffer#toString, TextDecoder drops a UTF-8 BOM, which JSON.parse rejects.
84+
return new TextDecoder().decode(contents.subarray(0, offset));
8485
} catch {
8586
return null;
8687
} finally {

0 commit comments

Comments
 (0)