Skip to content

Commit ce9b806

Browse files
felixlagaclaude
andauthored
fix(server): theme files saved with a UTF-8 BOM are published instead of rejected (pingdotgg#32405)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent 48bb784 commit ce9b806

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)