Skip to content

Commit 3c85c6b

Browse files
fix: csp nonce injection when no closing tag (#16281) (#16282)
Co-authored-by: 翠 / green <green@sapphi.red>
1 parent f1e67b6 commit 3c85c6b

File tree

1 file changed

+6
-1
lines changed
  • packages/vite/src/node/plugins

1 file changed

+6
-1
lines changed

packages/vite/src/node/plugins/html.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1189,8 +1189,13 @@ export function injectNonceAttributeTagHook(
11891189
parseRelAttr(attr.value).some((a) => processRelType.has(a)),
11901190
))
11911191
) {
1192+
// if the closing of the start tag includes a `/`, the offset should be 2 so the nonce
1193+
// is appended prior to the `/`
1194+
const appendOffset =
1195+
html[node.sourceCodeLocation!.startTag!.endOffset - 2] === '/' ? 2 : 1
1196+
11921197
s.appendRight(
1193-
node.sourceCodeLocation!.startTag!.endOffset - 1,
1198+
node.sourceCodeLocation!.startTag!.endOffset - appendOffset,
11941199
` nonce="${nonce}"`,
11951200
)
11961201
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy