Skip to content

Commit 97d68b1

Browse files
bfangerdummdidumm
andauthored
fix: Prevent crawling empty urls from <img src=""> (#8883)
The empty src was crawled as a relative url. On `/page/about` this would route to `/page/` which could 404 --------- Co-authored-by: Simon H <[email protected]>
1 parent 53d2723 commit 97d68b1

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

.changeset/lucky-tables-jam.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/kit': patch
3+
---
4+
5+
fix: prevent crawling empty urls (`<img src="">`)

packages/kit/src/core/postbuild/crawl.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ export function crawl(html) {
165165
} else if (name === 'rel') {
166166
rel = value;
167167
} else if (name === 'src') {
168-
hrefs.push(value);
168+
if (value) hrefs.push(value);
169169
} else if (name === 'srcset') {
170170
const candidates = [];
171171
let insideURL = true;
@@ -183,7 +183,7 @@ export function crawl(html) {
183183
candidates.push(value);
184184
for (const candidate of candidates) {
185185
const src = candidate.split(WHITESPACE)[0];
186-
hrefs.push(src);
186+
if (src) hrefs.push(src);
187187
}
188188
}
189189
} else {

packages/kit/src/core/postbuild/fixtures/basic-src/input.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
<head></head>
44
<body>
55
<img alt="A potato" src="/potato.jpg" />
6+
<img alt="empty" src="" />
67
</body>
78
</html>

0 commit comments

Comments
 (0)