added cssText check (#23)

* added cssText check

* added testing
This commit is contained in:
Filip Slatinac
2026-04-01 12:00:00 +08:00
committed by yz-yu
parent 5c23514fca
commit 44eddcc900
3 changed files with 24 additions and 23 deletions

View File

@@ -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;

View File

@@ -75,12 +75,14 @@ exports[`[html file]: block-element.html 1`] = `
exports[`[html file]: cors-style-sheet.html 1`] = `
"<!DOCTYPE html><html xmlns=\\"http://www.w3.org/1999/xhtml\\" lang=\\"en\\"><head>
<meta charset=\\"UTF-8\\" />
<meta name=\\"viewport\\" content=\\"width=device-width, initial-scale=1.0\\" />
<meta http-equiv=\\"X-UA-Compatible\\" content=\\"ie=edge\\" />
<title>with style sheet</title>
<link rel=\\"stylesheet\\" href=\\"https://cdn.jsdelivr.net/npm/pure@2.85.0/index.css\\" />
</head><body></body></html>"
<meta charset=\\"UTF-8\\" />
<meta name=\\"viewport\\" content=\\"width=device-width, initial-scale=1.0\\" />
<meta http-equiv=\\"X-UA-Compatible\\" content=\\"ie=edge\\" />
<title>with style sheet</title>
<link rel=\\"stylesheet\\" href=\\"https://cdn.jsdelivr.net/npm/pure@2.85.0/index.css\\" />
<link rel=\\"stylesheet\\" href=\\"\\" />
</head>
<body></body></html>"
`;
exports[`[html file]: dynamic-stylesheet.html 1`] = `

View File

@@ -1,16 +1,15 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>with style sheet</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/pure@2.85.0/index.css">
</head>
<body>
</body>
</html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>with style sheet</title>
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/pure@2.85.0/index.css"
/>
<link rel="stylesheet" href />
</head>
<body></body>
</html>