Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Prevent crawling empty urls from <img src=""> #8883

Merged
merged 2 commits into from
Feb 6, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix: Prevent crawling empty url from <img src="">
The empty src was crawled as a relative url.
On `/page/about` this would route to `/page/` which could 404
  • Loading branch information
bfanger committed Feb 4, 2023
commit d931cf0c5649f456a9c9f91e3c481b35c73daad1
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
---

Prevent crawling empty urls <img src="">
dummdidumm marked this conversation as resolved.
Show resolved Hide resolved
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>