diff --git a/packages/bundler-plugins/src/core/utils.ts b/packages/bundler-plugins/src/core/utils.ts index 2436147cc610..ce47ff86b65f 100644 --- a/packages/bundler-plugins/src/core/utils.ts +++ b/packages/bundler-plugins/src/core/utils.ts @@ -295,6 +295,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(/; @@ -292,6 +294,49 @@ describe('serializeIgnoreOptions', () => { }); }); +describe('code injection in HTML', () => { + afterEach(() => { + vi.restoreAllMocks(); + }); + + it.each([ + '', + '', + '