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: #9369, newline after comma in srcset attribute cause build failure #9388

Merged
merged 3 commits into from
Mar 10, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
5 changes: 5 additions & 0 deletions .changeset/late-berries-glow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

fix: #9369 newline after comma in srcset attribute causes build failure
7 changes: 5 additions & 2 deletions packages/kit/src/core/postbuild/crawl.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
/>
<img
alt="Troublesome srcset"
src="issue-9369.png"
srcset="/issue-9369_newline-after-comma-is-bad.png,
/issue-9369_800px.png 800,"
/>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -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": []
}