Skip to content

Commit 6cb8dff

Browse files
committed
fix: accept empty script blocks with spaces
Signed-off-by: Andres Correa Casablanca <andreu@kindspells.dev>
1 parent e2041b2 commit 6cb8dff

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

@kindspells/astro-shield/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@kindspells/astro-shield",
3-
"version": "1.7.0",
3+
"version": "1.7.1",
44
"description": "Astro integration to enhance your website's security with SubResource Integrity hashes, Content-Security-Policy headers, and other techniques.",
55
"private": false,
66
"type": "module",

@kindspells/astro-shield/src/core.mts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,10 @@ export const updateStaticPageSriHashes = async (
175175
// biome-ignore lint/suspicious/noAssignInExpressions: safe
176176
while ((match = regex.exec(content)) !== null) {
177177
const attrs = match.groups?.attrs?.trim() ?? ''
178-
const elemContent = match.groups?.content ?? ''
178+
179+
// We trim elemContent ONLY if it's made out of 100% whitespace characters
180+
const _elemContent = match.groups?.content ?? ''
181+
const elemContent = _elemContent.trim() === '' ? '' : _elemContent
179182

180183
let sriHash: string | undefined = undefined
181184
let setCrossorigin = false
@@ -320,7 +323,10 @@ export const updateDynamicPageSriHashes = (
320323
// biome-ignore lint/suspicious/noAssignInExpressions: safe
321324
while ((match = regex.exec(content)) !== null) {
322325
const attrs = match.groups?.attrs?.trim() ?? ''
323-
const elemContent = match.groups?.content ?? ''
326+
327+
// We trim elemContent ONLY if it's made out of 100% whitespace characters
328+
const _elemContent = match.groups?.content ?? ''
329+
const elemContent = _elemContent.trim() === '' ? '' : _elemContent
324330

325331
let sriHash: string | undefined = undefined
326332
let setCrossorigin = false

0 commit comments

Comments
 (0)