Skip to content

Commit

Permalink
Merge pull request #102 from Gaspar-Cdv/fix-escape-javascript-in-scri…
Browse files Browse the repository at this point in the history
…pt-tag

[FIX] escape closing script tag and opening comment tag
  • Loading branch information
richardtallent authored Nov 3, 2024
2 parents ae4368c + 5e002e1 commit 29dc598
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const defaultConfig = { useRecommendedBuildConfig: true, removeViteModuleLoader:
export function replaceScript(html: string, scriptFilename: string, scriptCode: string, removeViteModuleLoader = false): string {
const reScript = new RegExp(`<script([^>]*?) src="[./]*${scriptFilename}"([^>]*)></script>`)
const preloadMarker = /"?__VITE_PRELOAD__"?/g
const newCode = scriptCode.replace(preloadMarker, "void 0")
const newCode = scriptCode.replace(preloadMarker, "void 0").replace(/(<)(\/script>|!--)/g, '\\x3C$2')
const inlined = html.replace(reScript, (_, beforeSrc, afterSrc) => `<script${beforeSrc}${afterSrc}>${newCode}</script>`)
return removeViteModuleLoader ? _removeViteModuleLoader(inlined) : inlined
}
Expand Down

0 comments on commit 29dc598

Please sign in to comment.