From 97d68b1381c1e0d052a0978824e96b9f50d248a9 Mon Sep 17 00:00:00 2001 From: Bob Fanger Date: Mon, 6 Feb 2023 15:52:51 +0100 Subject: [PATCH] fix: Prevent crawling empty urls from (#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 <5968653+dummdidumm@users.noreply.github.com> --- .changeset/lucky-tables-jam.md | 5 +++++ packages/kit/src/core/postbuild/crawl.js | 4 ++-- .../kit/src/core/postbuild/fixtures/basic-src/input.html | 1 + 3 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 .changeset/lucky-tables-jam.md diff --git a/.changeset/lucky-tables-jam.md b/.changeset/lucky-tables-jam.md new file mode 100644 index 000000000000..2b334b36f876 --- /dev/null +++ b/.changeset/lucky-tables-jam.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/kit': patch +--- + +fix: prevent crawling empty urls (``) diff --git a/packages/kit/src/core/postbuild/crawl.js b/packages/kit/src/core/postbuild/crawl.js index 255d6e443e65..fd1bd4c9e683 100644 --- a/packages/kit/src/core/postbuild/crawl.js +++ b/packages/kit/src/core/postbuild/crawl.js @@ -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; @@ -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 { diff --git a/packages/kit/src/core/postbuild/fixtures/basic-src/input.html b/packages/kit/src/core/postbuild/fixtures/basic-src/input.html index 82c55c8f2780..52d4ee72b077 100644 --- a/packages/kit/src/core/postbuild/fixtures/basic-src/input.html +++ b/packages/kit/src/core/postbuild/fixtures/basic-src/input.html @@ -3,5 +3,6 @@ A potato + empty