Skip to content

Commit

Permalink
Merge pull request #565 from lawren/issue-564
Browse files Browse the repository at this point in the history
fix: #564 resolves issue with element.replace on non-string elements
  • Loading branch information
vejja authored Nov 22, 2024
2 parents 5ab0873 + d51c300 commit 5f508b5
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/runtime/nitro/plugins/40-cspSsrNonce.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ export default defineNitroPlugin((nitroApp) => {
const sections = ['body', 'bodyAppend', 'bodyPrepend', 'head'] as Section[]
for (const section of sections) {
html[section] = html[section].map((element) => {
// Skip non-string elements
if (typeof element !== 'string') {
return element;
}
// Add nonce to all link tags
element = element.replace(LINK_RE, (match, rest) => {
return `<link nonce="${nonce}"` + rest
Expand Down

0 comments on commit 5f508b5

Please # to comment.