Skip to content

Commit

Permalink
fix: accept empty script blocks with spaces
Browse files Browse the repository at this point in the history
Signed-off-by: Andres Correa Casablanca <[email protected]>
  • Loading branch information
castarco committed Nov 2, 2024
1 parent e2041b2 commit 6cb8dff
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion @kindspells/astro-shield/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@kindspells/astro-shield",
"version": "1.7.0",
"version": "1.7.1",
"description": "Astro integration to enhance your website's security with SubResource Integrity hashes, Content-Security-Policy headers, and other techniques.",
"private": false,
"type": "module",
Expand Down
10 changes: 8 additions & 2 deletions @kindspells/astro-shield/src/core.mts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,10 @@ export const updateStaticPageSriHashes = async (
// biome-ignore lint/suspicious/noAssignInExpressions: safe
while ((match = regex.exec(content)) !== null) {
const attrs = match.groups?.attrs?.trim() ?? ''
const elemContent = match.groups?.content ?? ''

// We trim elemContent ONLY if it's made out of 100% whitespace characters
const _elemContent = match.groups?.content ?? ''
const elemContent = _elemContent.trim() === '' ? '' : _elemContent

let sriHash: string | undefined = undefined
let setCrossorigin = false
Expand Down Expand Up @@ -320,7 +323,10 @@ export const updateDynamicPageSriHashes = (
// biome-ignore lint/suspicious/noAssignInExpressions: safe
while ((match = regex.exec(content)) !== null) {
const attrs = match.groups?.attrs?.trim() ?? ''
const elemContent = match.groups?.content ?? ''

// We trim elemContent ONLY if it's made out of 100% whitespace characters
const _elemContent = match.groups?.content ?? ''
const elemContent = _elemContent.trim() === '' ? '' : _elemContent

let sriHash: string | undefined = undefined
let setCrossorigin = false
Expand Down

0 comments on commit 6cb8dff

Please sign in to comment.