Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

Accept only three- and six-digit hex for the iPhone theme color.

Shreerama979e7c6a8a067
diff --git a/src/lib/browser-chrome.test.ts b/src/lib/browser-chrome.test.ts
index 09a17fb31f..fa180e19d8 100644
--- a/src/lib/browser-chrome.test.ts
+++ b/src/lib/browser-chrome.test.ts
@@ -41,6 +41,17 @@ describe("theme-color follows the skin ground", () => {
expect(bar.getAttribute("content")).toBe("#0b0c0b");
});
+ it("accepts a three-digit or six-digit hex color and refuses nine digits", () => {
+ const short = doc();
+ expect(applyThemeColor("#abc", short)).toBe(true);
+ expect(short.created[0].getAttribute("content")).toBe("#abc");
+ const full = doc();
+ expect(applyThemeColor("#121212", full)).toBe(true);
+ const nine = doc();
+ expect(applyThemeColor("#123456789", nine)).toBe(false);
+ expect(nine.created).toHaveLength(0);
+ });
+
it("leaves the bar alone when the surface is not a hex color", () => {
const page = doc();
expect(applyThemeColor("var(--color-app)", page)).toBe(false);
diff --git a/src/lib/browser-chrome.ts b/src/lib/browser-chrome.ts
index ac60774a59..8b7f06c0eb 100644
--- a/src/lib/browser-chrome.ts
+++ b/src/lib/browser-chrome.ts
@@ -1,7 +1,7 @@
/** Safari on iPhone paints its bottom bar from the root scheme and from
* theme-color. The skin lives in --color-app; the bar has to be told. */
-const SURFACE = /^#[0-9a-fA-F]{3}(?:[0-9a-fA-F]{3}){1,2}$/;
+const SURFACE = /^#[0-9a-fA-F]{3}(?:[0-9a-fA-F]{3})?$/;
type ThemeColorMeta = {
getAttribute(name: string): string | null;