The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): the origin guard splits only after a real 'use strict' directive
Teknium709e2adec518
diff --git a/apps/desktop/src/contrib/plugin-preview.test.ts b/apps/desktop/src/contrib/plugin-preview.test.tsindex e1c9202aa3a..9632054161d 100644--- a/apps/desktop/src/contrib/plugin-preview.test.ts+++ b/apps/desktop/src/contrib/plugin-preview.test.ts@@ -221,6 +221,18 @@ describe('ctx.preview.executeJavaScript', () => {).resolves.toBe(true)})+ it("leaves a 'use strict' string that is not a directive in one piece", async () => {+ openPage()+ const { ctx, id } = pluginWith([CAPABILITY])++ grantPreviewScript(id, 'https://mail.example.com')++ await expect(ctx.preview.executeJavaScript("'use strict'\n.toUpperCase()")).resolves.toBe('USE STRICT')+ await expect(+ ctx.preview.executeJavaScript("'use strict'\n// strict body\n;(function () { return this === undefined })()")+ ).resolves.toBe(true)+ })+it("a revoke that storage refuses to save still binds this window and isn't shown as done", async () => {openPage()const { ctx, id } = pluginWith([CAPABILITY])diff --git a/apps/desktop/src/contrib/plugin-preview.ts b/apps/desktop/src/contrib/plugin-preview.tsindex bed8e635d39..443315de607 100644--- a/apps/desktop/src/contrib/plugin-preview.ts+++ b/apps/desktop/src/contrib/plugin-preview.ts@@ -42,8 +42,10 @@ export interface PluginPreview {const ORIGIN_PROBE = 'window.location.origin'// A leading `'use strict'` directive must stay first or the script silently-// leaves strict mode, so the guard goes right after it.-const STRICT_PROLOGUE = /^\s*(['"])use strict\1[ \t]*(?:;|\r?\n|$)/+// leaves strict mode, so the guard goes right after it. A newline ends the+// directive only when the next line cannot continue the expression+// (`'use strict'\n.toUpperCase()` is one expression, not a directive).+const STRICT_PROLOGUE = /^\s*(['"])use strict\1[ \t]*(?:;|\r?\n(?=\s*(?:\/[/*]|[^\s.([`+\-*/%<>=&|^?,]))|$)//** Inserts a guard statement; the plugin's script keeps its completion value. */function originGuarded(origin: string, code: string): string {