The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 06:00 UTC
fix(themes): keep escaped quotes in CSS text (#39296)
Co-authored-by: Julius Marminge <julius0216@outlook.com>
Wout Stiens committed
Nov 19, 2026 at 21:09 UTC
1d3932570c8bdc3ec52465270e7d66db4ce58db5
3 files changed
+66
-11
packages/shared/src/themeCss.test.ts
+4
@@ -21,6 +21,10 @@ describe("themeCssValueFetches", () => {
21
["background-image", `url("${SVG_WITH_OWN_GRADIENT}")`, false],
22
// The url( sits inside a string, so the address after that string is a real remote url().
23
["content", `"url('data:" url("https://evil.example/a") "'"`, true],
24
+ ["--leak", '/* " */ url(https://evil.example/a) /* " */', true],
25
+ ["content", String.raw`"Theme preview: \"ready\""`, false],
26
+ ["--label", String.raw`'It\'s ready'`, false],
27
+ ["content", String.raw`url("#icon") / "The \"ready\" icon"`, false],
28
["filter", 'url("#blur")', false],
29
["background-image", "var(--pattern)", false],
30
["color", "red", false],
packages/shared/src/themeCss.ts
+18
-11
@@ -9,19 +9,25 @@ const URL_NOT_LOCAL = /url\((?![ \t\n\f\r]*["']?(?:data:|#))/i;
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");
12
+const CSS_TOKENS = new RegExp(String.raw`\/\*[\s\S]*?\*\/|${URL_OR_STRING}`, "gi");
13
14
/**
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.
15
+ * The code with its strings and comments removed, keeping `url(` where a quoted url() can load a
16
+ * file. A declaration value keeps a comment or quoted url() that holds an escape. In a stylesheet
17
+ * an unquoted url() 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) => {
20
+ return code.replace(CSS_TOKENS, (token, address?: string, urlString?: string) => {
21
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;
22
+ if (url !== undefined) {
23
+ if (!stylesheet && url.includes("\\")) return token;
24
+ return /^[ \t\n\f\r]*["']?(?:data:|#)/i.test(url) ? "" : "url(";
25
+ }
26
+ if (token.startsWith("/*")) {
27
+ if (stylesheet) return "";
28
+ return token.includes("\\") ? token : " ";
29
+ }
30
+ return /^["']/.test(token) ? "" : token;
31
});
32
}
33
@@ -31,11 +37,12 @@ function fetchesOutsideStrings(code: string): boolean {
37
38
/**
39
* Whether one declaration value can load a remote file. Clients drop those declarations.
34
- * A value with var() stays unparsed until use, and an escape can spell `var` or `url` in it,
35
- * so every value that still has a backslash is refused.
40
+ * Values with var() can keep escapes that spell `var` or `url`. Refuse escapes that survive
41
+ * removing plain strings, including escapes in URL addresses.
42
*/
43
export function themeCssValueFetches(value: string): boolean {
38
- return value.includes("\\") || fetchesOutsideStrings(withoutStrings(value, false));
44
+ const code = withoutStrings(value, false);
45
+ return code.includes("\\") || fetchesOutsideStrings(code);
46
}
47
48
/** A text check for early feedback. CSS escapes can dodge it; the client check is the guard. */
scripts/scenarios/theme-renders-escaped-quotation-marks.e2e.ts
new
+44
@@ -0,0 +1,44 @@
1
+/// <reference lib="dom" />
2
+import { expect } from "e2e";
3
+
4
+import { test, WEB } from "./t3.ts";
5
+
6
+const CONTENT = String.raw`"Theme preview: \"ready\""`;
7
+
8
+test(
9
+ "A theme renders custom text containing quotation marks",
10
+ WEB,
11
+ async ({ t3, app, screen, browser }) => {
12
+ await t3.project("demo");
13
+ await t3.open("/settings/appearance");
14
+ await screen.getByRole("button", "Add theme", { exact: true }).tap();
15
+ const dialog = screen.getByRole("dialog", "Add a theme");
16
+ await dialog.getByRole("textbox", "Theme JSON").fill(
17
+ JSON.stringify({
18
+ version: 1,
19
+ name: "Quoted Preview",
20
+ appearance: "light",
21
+ colors: { canvas: "#ffffff", accent: "#734ee4" },
22
+ css: `[data-settings-page-scroll]::before { display: block; content: ${CONTENT}; }`,
23
+ }),
24
+ );
25
+ await dialog.getByRole("button", "Add theme", { exact: true }).tap();
26
+ await dialog.waitFor({ state: "hidden" });
27
+ await screen.getByRole("button", "Use Quoted Preview theme", { exact: true }).tap();
28
+
29
+ try {
30
+ await expect
31
+ .poll(
32
+ () =>
33
+ browser.evaluate(() => {
34
+ const settings = document.querySelector("[data-settings-page-scroll]");
35
+ return settings ? getComputedStyle(settings, "::before").content : "";
36
+ }),
37
+ { message: "The selected theme displays its custom text with quotation marks" },
38
+ )
39
+ .toBe(CONTENT);
40
+ } finally {
41
+ await app.screenshot("theme-custom-text");
42
+ }
43
+ },
44
+);