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:
@@ -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"
|
||||
|
||||
@@ -293,14 +293,17 @@ function _patchHtmlFiles(scriptDir: string, combinedScript: string, logToFile: (
|
||||
logToFile(`[OBSERVER] ${spec.name} removed old inline script block`);
|
||||
}
|
||||
// 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>')) {
|
||||
html = html.replace('</body>',
|
||||
`\n${inlineBlock}\n</body>`);
|
||||
`\n${safeInlineBlock}\n</body>`);
|
||||
logToFile(`[OBSERVER] ${spec.name} inline script INSERTED before </body>`);
|
||||
} else {
|
||||
// Fallback: insert before </html>
|
||||
html = html.replace('</html>',
|
||||
`\n${inlineBlock}\n</html>`);
|
||||
`\n${safeInlineBlock}\n</html>`);
|
||||
logToFile(`[OBSERVER] ${spec.name} inline script INSERTED before </html> (fallback)`);
|
||||
}
|
||||
// SAFETY: Final validation before write
|
||||
|
||||
Reference in New Issue
Block a user