Skip to content

Commit

Permalink
fix: Prevent crawling empty urls from <img src=""> (#8883)
Browse files Browse the repository at this point in the history
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 <5968653+dummdidumm@users.noreply.github.com>
  • Loading branch information
bfanger and dummdidumm authored Feb 6, 2023
1 parent 53d2723 commit 97d68b1
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/lucky-tables-jam.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

fix: prevent crawling empty urls (`<img src="">`)
4 changes: 2 additions & 2 deletions packages/kit/src/core/postbuild/crawl.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ export function crawl(html) {
} else if (name === 'rel') {
rel = value;
} else if (name === 'src') {
hrefs.push(value);
if (value) hrefs.push(value);
} else if (name === 'srcset') {
const candidates = [];
let insideURL = true;
Expand All @@ -183,7 +183,7 @@ export function crawl(html) {
candidates.push(value);
for (const candidate of candidates) {
const src = candidate.split(WHITESPACE)[0];
hrefs.push(src);
if (src) hrefs.push(src);
}
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
<head></head>
<body>
<img alt="A potato" src="/potato.jpg" />
<img alt="empty" src="" />
</body>
</html>

0 comments on commit 97d68b1

Please sign in to comment.