Open-source Grok Bot alternative for named AI teammates. Local-first desktop, web, and mobile clients with per-bot tools, instructions, and memory. Independent fork of T3 Code.
Handle favicon links when href precedes rel
Julius Marmingee6c5a4a4bb96
diff --git a/apps/server/src/projectFaviconRoute.test.ts b/apps/server/src/projectFaviconRoute.test.tsindex b0f0273cf..e8b826d7b 100644--- a/apps/server/src/projectFaviconRoute.test.ts+++ b/apps/server/src/projectFaviconRoute.test.ts@@ -115,4 +115,41 @@ describe("tryHandleProjectFaviconRequest", () => {expect(response.body).toBe("<svg>brand</svg>");});});++ it("resolves icon link when href appears before rel in HTML", async () => {+ const projectDir = makeTempDir("t3code-favicon-route-html-order-");+ const iconPath = path.join(projectDir, "public", "brand", "logo.svg");+ fs.mkdirSync(path.dirname(iconPath), { recursive: true });+ fs.writeFileSync(path.join(projectDir, "index.html"), '<link href="/brand/logo.svg" rel="icon">');+ fs.writeFileSync(iconPath, "<svg>brand-html-order</svg>", "utf8");++ await withRouteServer(async (baseUrl) => {+ const pathname = `/api/project-favicon?cwd=${encodeURIComponent(projectDir)}`;+ const response = await request(baseUrl, pathname);+ expect(response.statusCode).toBe(200);+ expect(response.contentType).toContain("image/svg+xml");+ expect(response.body).toBe("<svg>brand-html-order</svg>");+ });+ });++ it("resolves object-style icon metadata when href appears before rel", async () => {+ const projectDir = makeTempDir("t3code-favicon-route-obj-order-");+ const iconPath = path.join(projectDir, "public", "brand", "obj.svg");+ fs.mkdirSync(path.dirname(iconPath), { recursive: true });+ fs.mkdirSync(path.join(projectDir, "src"), { recursive: true });+ fs.writeFileSync(+ path.join(projectDir, "src", "root.tsx"),+ 'const links = [{ href: "/brand/obj.svg", rel: "icon" }];',+ "utf8",+ );+ fs.writeFileSync(iconPath, "<svg>brand-obj-order</svg>", "utf8");++ await withRouteServer(async (baseUrl) => {+ const pathname = `/api/project-favicon?cwd=${encodeURIComponent(projectDir)}`;+ const response = await request(baseUrl, pathname);+ expect(response.statusCode).toBe(200);+ expect(response.contentType).toContain("image/svg+xml");+ expect(response.body).toBe("<svg>brand-obj-order</svg>");+ });+ });});diff --git a/apps/server/src/projectFaviconRoute.ts b/apps/server/src/projectFaviconRoute.tsindex 5b224ca56..4d66f0e86 100644--- a/apps/server/src/projectFaviconRoute.ts+++ b/apps/server/src/projectFaviconRoute.ts@@ -44,9 +44,11 @@ const ICON_SOURCE_FILES = ["src/index.html",];-// Matches <link rel="icon" href="..."> or { rel: "icon", href: "..." } patterns.-const LINK_ICON_HTML_RE = /<link[^>]*rel=["'](?:icon|shortcut icon)["'][^>]*href=["']([^"'?]+)/i;-const LINK_ICON_OBJ_RE = /rel:\s*["'](?:icon|shortcut icon)["'][^}]*href:\s*["']([^"'?]+)/i;+// Matches <link ...> tags or object-like icon metadata where rel/href can appear in any order.+const LINK_ICON_HTML_RE =+ /<link\b(?=[^>]*\brel=["'](?:icon|shortcut icon)["'])(?=[^>]*\bhref=["']([^"'?]+))[^>]*>/i;+const LINK_ICON_OBJ_RE =+ /(?=[^}]*\brel\s*:\s*["'](?:icon|shortcut icon)["'])(?=[^}]*\bhref\s*:\s*["']([^"'?]+))[^}]*/i;function extractIconHref(source: string): string | null {const htmlMatch = source.match(LINK_ICON_HTML_RE);