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([ + '', + '', + '