Skip to content

Commit

Permalink
fix: #564 resolves issue with element.replace on non-string elements
Browse files Browse the repository at this point in the history
  • Loading branch information
lawren committed Nov 21, 2024
1 parent 5ab0873 commit d51c300
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 d51c300

Please # to comment.