fix(html-patcher): escape $ in inline script replacement to prevent String.replace() special pattern corruption — root cause of observer SyntaxError #task-619

This commit is contained in:
Variet Worker
2026-04-13 12:22:02 +09:00
parent a214ab029f
commit d6ed8764b8
2 changed files with 6 additions and 3 deletions

View File

@@ -2,7 +2,7 @@
"name": "gravity-bridge", "name": "gravity-bridge",
"displayName": "Gravity Bridge", "displayName": "Gravity Bridge",
"description": "Discord-based unified approval system for Antigravity AI interactions.", "description": "Discord-based unified approval system for Antigravity AI interactions.",
"version": "0.5.37", "version": "0.5.38",
"publisher": "variet", "publisher": "variet",
"engines": { "engines": {
"vscode": "^1.100.0" "vscode": "^1.100.0"

View File

@@ -293,14 +293,17 @@ function _patchHtmlFiles(scriptDir: string, combinedScript: string, logToFile: (
logToFile(`[OBSERVER] ${spec.name} removed old inline script block`); logToFile(`[OBSERVER] ${spec.name} removed old inline script block`);
} }
// Insert BEFORE </body> (not </html>) to ensure Electron executes it // Insert BEFORE </body> (not </html>) 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('</body>')) { if (html.includes('</body>')) {
html = html.replace('</body>', html = html.replace('</body>',
`\n${inlineBlock}\n</body>`); `\n${safeInlineBlock}\n</body>`);
logToFile(`[OBSERVER] ${spec.name} inline script INSERTED before </body>`); logToFile(`[OBSERVER] ${spec.name} inline script INSERTED before </body>`);
} else { } else {
// Fallback: insert before </html> // Fallback: insert before </html>
html = html.replace('</html>', html = html.replace('</html>',
`\n${inlineBlock}\n</html>`); `\n${safeInlineBlock}\n</html>`);
logToFile(`[OBSERVER] ${spec.name} inline script INSERTED before </html> (fallback)`); logToFile(`[OBSERVER] ${spec.name} inline script INSERTED before </html> (fallback)`);
} }
// SAFETY: Final validation before write // SAFETY: Final validation before write