We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
vitejs
Learn more about funding links in repositories.
Report abuse
1 parent f1e67b6 commit 3c85c6bCopy full SHA for 3c85c6b
packages/vite/src/node/plugins/html.ts
@@ -1189,8 +1189,13 @@ export function injectNonceAttributeTagHook(
1189
parseRelAttr(attr.value).some((a) => processRelType.has(a)),
1190
))
1191
) {
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
+
1197
s.appendRight(
- node.sourceCodeLocation!.startTag!.endOffset - 1,
1198
+ node.sourceCodeLocation!.startTag!.endOffset - appendOffset,
1199
` nonce="${nonce}"`,
1200
)
1201
}
0 commit comments