From a92a768c964236fe15519d78bdb54e583e26e776 Mon Sep 17 00:00:00 2001 From: Martin Sonnberger Date: Mon, 12 Oct 2026 13:01:31 +0200 Subject: [PATCH] fix(bundler-plugins): Escape JSON in generated injection code Co-Authored-By: GPT-6 --- packages/bundler-plugins/src/core/utils.ts | 11 +++-- .../bundler-plugins/test/core/utils.test.ts | 47 ++++++++++++++++++- 2 files changed, 54 insertions(+), 4 deletions(-) diff --git a/packages/bundler-plugins/src/core/utils.ts b/packages/bundler-plugins/src/core/utils.ts index f0d8952dc131..c8dd57597cc0 100644 --- a/packages/bundler-plugins/src/core/utils.ts +++ b/packages/bundler-plugins/src/core/utils.ts @@ -308,6 +308,11 @@ export function determineReleaseName(): string | undefined { ); } +function stringifyForCodeInjection(value: unknown): string | undefined { + // Bundles may be inlined in HTML, where JSON quoting does not escape script tags or HTML comments. + return JSON.stringify(value)?.replace(/; @@ -284,6 +286,49 @@ describe('generateModuleMetadataInjectorCode', () => { }); }); +describe('code injection in HTML', () => { + afterEach(() => { + vi.restoreAllMocks(); + }); + + it.each([ + '', + '', + '