Skip to content

Commit 9e42ae6

Browse files
fix(server): serve html assets with utf-8 charset
1 parent 1e59b4c commit 9e42ae6

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,15 @@ describe("assetResponseHeaders", () => {
4444
"X-Content-Type-Options": "nosniff",
4545
});
4646
});
47+
48+
it("declares utf-8 for HTML assets so non-ASCII content renders correctly", () => {
49+
expect(assetResponseHeaders("/workspace/page.html")).toHaveProperty(
50+
"Content-Type",
51+
"text/html; charset=utf-8",
52+
);
53+
expect(assetResponseHeaders("/workspace/PAGE.HTM")).toHaveProperty(
54+
"Content-Type",
55+
"text/html; charset=utf-8",
56+
);
57+
});
4758
});

‎apps/server/src/http.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,14 @@ const DESKTOP_RENDERER_ORIGINS = ["t3code://app", "t3code-dev://app"];
4646
const SVG_CONTENT_SECURITY_POLICY = "default-src 'none'; style-src 'unsafe-inline'; sandbox";
4747

4848
export function assetResponseHeaders(filePath: string): Record<string, string> {
49+
const lowerPath = filePath.toLowerCase();
4950
return {
5051
"Cache-Control": "private, max-age=3600",
5152
"X-Content-Type-Options": "nosniff",
52-
...(filePath.toLowerCase().endsWith(".svg")
53+
...(lowerPath.endsWith(".html") || lowerPath.endsWith(".htm")
54+
? { "Content-Type": "text/html; charset=utf-8" }
55+
: {}),
56+
...(lowerPath.endsWith(".svg")
5357
? { "Content-Security-Policy": SVG_CONTENT_SECURITY_POLICY }
5458
: {}),
5559
};

0 commit comments

Comments
 (0)