diff --git a/.changeset/late-berries-glow.md b/.changeset/late-berries-glow.md new file mode 100644 index 000000000000..dedf99fc1e63 --- /dev/null +++ b/.changeset/late-berries-glow.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/kit': patch +--- + +fix: handle srcset attributes with newline after comma diff --git a/packages/kit/src/core/postbuild/crawl.js b/packages/kit/src/core/postbuild/crawl.js index 4132ba6c136e..4d96d3cce7fc 100644 --- a/packages/kit/src/core/postbuild/crawl.js +++ b/packages/kit/src/core/postbuild/crawl.js @@ -179,12 +179,15 @@ export function crawl(html, base) { let insideURL = true; value = value.trim(); for (let i = 0; i < value.length; i++) { - if (value[i] === ',' && (!insideURL || (insideURL && value[i + 1] === ' '))) { + if ( + value[i] === ',' && + (!insideURL || (insideURL && WHITESPACE.test(value[i + 1]))) + ) { candidates.push(value.slice(0, i)); value = value.substring(i + 1).trim(); i = 0; insideURL = true; - } else if (value[i] === ' ') { + } else if (WHITESPACE.test(value[i])) { insideURL = false; } } diff --git a/packages/kit/src/core/postbuild/fixtures/basic-srcset/input.html b/packages/kit/src/core/postbuild/fixtures/basic-srcset/input.html index 2cf4e81e6d6b..777dd36ac034 100644 --- a/packages/kit/src/core/postbuild/fixtures/basic-srcset/input.html +++ b/packages/kit/src/core/postbuild/fixtures/basic-srcset/input.html @@ -7,5 +7,11 @@ src="header.png" srcset="https://example.com/w_200,q_100/header.png 200w, header640.png 640w, header960.png 960w, header1024.png 1024w, header.png" /> + Troublesome srcset diff --git a/packages/kit/src/core/postbuild/fixtures/basic-srcset/output.json b/packages/kit/src/core/postbuild/fixtures/basic-srcset/output.json index 536c3d3f3a58..44129a2b617d 100644 --- a/packages/kit/src/core/postbuild/fixtures/basic-srcset/output.json +++ b/packages/kit/src/core/postbuild/fixtures/basic-srcset/output.json @@ -5,7 +5,10 @@ "/header640.png", "/header960.png", "/header1024.png", - "/header.png" + "/header.png", + "/issue-9369.png", + "/issue-9369_newline-after-comma-is-bad.png", + "/issue-9369_800px.png" ], "ids": [] }