From 44eddcc900831206b1e15a141a52b94f4f4aadc8 Mon Sep 17 00:00:00 2001 From: Filip Slatinac Date: Wed, 1 Apr 2026 12:00:00 +0800 Subject: [PATCH] added cssText check (#23) * added cssText check * added testing --- src/snapshot.ts | 6 +++--- test/__snapshots__/integration.ts.snap | 14 +++++++------ test/html/cors-style-sheet.html | 27 +++++++++++++------------- 3 files changed, 24 insertions(+), 23 deletions(-) diff --git a/src/snapshot.ts b/src/snapshot.ts index 8c8233e1..167768f2 100644 --- a/src/snapshot.ts +++ b/src/snapshot.ts @@ -146,11 +146,11 @@ export function transformAttribute( value: string, ): string { // relative path in attribute - if (name === 'src' || name === 'href') { + if (name === 'src' || (name === 'href' && value)) { return absoluteToDoc(doc, value); - } else if (name === 'srcset') { + } else if (name === 'srcset' && value) { return getAbsoluteSrcsetString(doc, value); - } else if (name === 'style') { + } else if (name === 'style' && value) { return absoluteToStylesheet(value, location.href); } else { return value; diff --git a/test/__snapshots__/integration.ts.snap b/test/__snapshots__/integration.ts.snap index f04f33ad..363fd658 100644 --- a/test/__snapshots__/integration.ts.snap +++ b/test/__snapshots__/integration.ts.snap @@ -75,12 +75,14 @@ exports[`[html file]: block-element.html 1`] = ` exports[`[html file]: cors-style-sheet.html 1`] = ` " - - - - with style sheet - -" + + + + with style sheet + + + + " `; exports[`[html file]: dynamic-stylesheet.html 1`] = ` diff --git a/test/html/cors-style-sheet.html b/test/html/cors-style-sheet.html index 06dddaa2..741a1366 100644 --- a/test/html/cors-style-sheet.html +++ b/test/html/cors-style-sheet.html @@ -1,16 +1,15 @@ - - - - - - with style sheet - - - - - - - - \ No newline at end of file + + + + + with style sheet + + + + +