From d6ed8764b87dca658742ae78fea1973917290846 Mon Sep 17 00:00:00 2001 From: Variet Worker Date: Mon, 13 Apr 2026 12:22:02 +0900 Subject: [PATCH] =?UTF-8?q?fix(html-patcher):=20escape=20$=20in=20inline?= =?UTF-8?q?=20script=20replacement=20to=20prevent=20String.replace()=20spe?= =?UTF-8?q?cial=20pattern=20corruption=20=E2=80=94=20root=20cause=20of=20o?= =?UTF-8?q?bserver=20SyntaxError=20#task-619?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- extension/package.json | 2 +- extension/src/html-patcher.ts | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/extension/package.json b/extension/package.json index ea60906..a34e8c9 100644 --- a/extension/package.json +++ b/extension/package.json @@ -2,7 +2,7 @@ "name": "gravity-bridge", "displayName": "Gravity Bridge", "description": "Discord-based unified approval system for Antigravity AI interactions.", - "version": "0.5.37", + "version": "0.5.38", "publisher": "variet", "engines": { "vscode": "^1.100.0" diff --git a/extension/src/html-patcher.ts b/extension/src/html-patcher.ts index e749078..a32413f 100644 --- a/extension/src/html-patcher.ts +++ b/extension/src/html-patcher.ts @@ -293,14 +293,17 @@ function _patchHtmlFiles(scriptDir: string, combinedScript: string, logToFile: ( logToFile(`[OBSERVER] ${spec.name} removed old inline script block`); } // Insert BEFORE (not ) to ensure Electron executes it + // CRITICAL: Escape $ in inlineBlock to prevent String.replace() special patterns + // ($' = text after match, $& = matched text, etc.) which corrupt the JS code. + const safeInlineBlock = inlineBlock.replace(/\$/g, '$$$$'); if (html.includes('')) { html = html.replace('', - `\n${inlineBlock}\n`); + `\n${safeInlineBlock}\n`); logToFile(`[OBSERVER] ${spec.name} inline script INSERTED before `); } else { // Fallback: insert before html = html.replace('', - `\n${inlineBlock}\n`); + `\n${safeInlineBlock}\n`); logToFile(`[OBSERVER] ${spec.name} inline script INSERTED before (fallback)`); } // SAFETY: Final validation before write