The best way to control Claude Code, Codex and more from any computer or phone
fix(shared): theme CSS saves with escaped quotes and quoted comment markers (#39217)
Co-authored-by: Julius Marminge <julius0216@outlook.com>
Soroush Baraouf committed
Nov 19, 2026 at 12:56 UTC
3b4041a97a5ca84c4b8a3dac71287cf82190c7a7
2 files changed
+32
-11
packages/shared/src/themeCss.test.ts
+12
@@ -32,7 +32,19 @@ describe("themeCssValueFetches", () => {
32
describe("themeCssLoadsRemoteFiles", () => {
33
it.each([
34
['[data-chat-header]::after { content: "@import"; }', false],
35
+ ['.a::after { content: "say \\"@import\\""; }', false],
36
+ ['.a::after { content: "a\\\r\n@import"; }', false],
37
+ ['.a::after { content: "\\22\r\n@import"; }', false],
38
+ ['.a::after { content: "/*"; } /* note */ .b::after { content: "@import"; }', false],
39
+ ['/* @import "x.css"; */ .a::after { content: "*/"; }', false],
40
+ [
41
+ ".a { background-image: url(data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22%3E%3C!--/*@import*/--%3E%3C/svg%3E); }",
42
+ false,
43
+ ],
44
['@import "x.css";', true],
45
+ ['.a\\" {} @import "x.css"; .b\\" {}', true],
46
+ ['.a::after { content: "\\\\"; } @import "x.css";', true],
47
+ [".a { background: url(https://example.invalid/x.png); }", true],
48
])("%s", (css, loads) => {
49
expect(themeCssLoadsRemoteFiles(css)).toBe(loads);
50
});
packages/shared/src/themeCss.ts
+20
-11
@@ -3,16 +3,25 @@ import { THEME_COLOR_ROLES } from "./themePalettes.ts";
3
const FETCHES_BY_STRING = /image-set\(|\bsrc\(/i;
4
// Only CSS whitespace may come first. \s also matches U+00A0, which makes the address relative.
5
const URL_NOT_LOCAL = /url\((?![ \t\n\f\r]*["']?(?:data:|#))/i;
6
-// Read tokens left to right, as CSS does: a url( inside a string loads nothing, and a quote in an
7
-// unquoted url( is not a string. A quoted url() that is not data: or #id keeps `url(` for the check.
8
-const URL_OR_STRING =
9
- /url\((?![ \t\n\f\r]*["'])[^)]*|url\([ \t\n\f\r]*("[^"\n\r\f]*"|'[^'\n\r\f]*')|"[^"\n\r\f]*"|'[^'\n\r\f]*'/gi;
6
+// Read tokens left to right, as CSS does: a url( or /* inside a string loads nothing, and a quote
7
+// in an unquoted url( or after a backslash is not a string. A quoted url() that is not data: or #id
8
+// keeps `url(` for the check.
9
+const ESCAPE = String.raw`\\(?:(?:[0-9a-fA-F]{6}|[0-9a-fA-F]{1,5}(?![0-9a-fA-F]))(?:\r\n|[\n\r\f])?|\r\n|[^0-9a-fA-F])`;
10
+const STRING = String.raw`"(?:${ESCAPE}|[^"\\\n\r\f])*"|'(?:${ESCAPE}|[^'\\\n\r\f])*'`;
11
+const URL_OR_STRING = String.raw`url\((?![ \t\n\f\r]*["'])([^)]*)|url\([ \t\n\f\r]*(${STRING})|${STRING}|${ESCAPE}`;
12
+const VALUE_TOKENS = new RegExp(URL_OR_STRING, "gi");
13
+const STYLESHEET_TOKENS = new RegExp(String.raw`\/\*[\s\S]*?\*\/|${URL_OR_STRING}`, "gi");
14
11
-/** The code with its strings removed, keeping `url(` where a quoted url() can load a file. */
12
-function withoutStrings(code: string): string {
13
- return code.replace(URL_OR_STRING, (token, urlString: string | undefined) => {
14
- if (urlString !== undefined) return /^["'](?:data:|#)/i.test(urlString) ? "" : "url(";
15
- return token.startsWith('"') || token.startsWith("'") ? "" : token;
15
+/**
16
+ * The code with its strings removed, keeping `url(` where a quoted url() can load a file. A
17
+ * stylesheet also loses its comments, and an unquoted url() there is judged by its address too.
18
+ */
19
+function withoutStrings(code: string, stylesheet: boolean): string {
20
+ const tokens = stylesheet ? STYLESHEET_TOKENS : VALUE_TOKENS;
21
+ return code.replace(tokens, (token, address?: string, urlString?: string) => {
22
+ const url = stylesheet ? (address ?? urlString) : urlString;
23
+ if (url !== undefined) return /^[ \t\n\f\r]*["']?(?:data:|#)/i.test(url) ? "" : "url(";
24
+ return /^["'/]/.test(token) ? "" : token;
25
});
26
}
27
@@ -26,12 +35,12 @@ function fetchesOutsideStrings(code: string): boolean {
35
* so every value that still has a backslash is refused.
36
*/
37
export function themeCssValueFetches(value: string): boolean {
29
- return value.includes("\\") || fetchesOutsideStrings(withoutStrings(value));
38
+ return value.includes("\\") || fetchesOutsideStrings(withoutStrings(value, false));
39
}
40
41
/** A text check for early feedback. CSS escapes can dodge it; the client check is the guard. */
42
export function themeCssLoadsRemoteFiles(css: string): boolean {
34
- const code = withoutStrings(css.replace(/\/\*[\s\S]*?\*\//g, ""));
43
+ const code = withoutStrings(css, true);
44
return /@import/i.test(code) || fetchesOutsideStrings(code);
45
}
46