Skip to content

Commit

Permalink
fix: handle srcset attributes with newline after comma (#9388)
Browse files Browse the repository at this point in the history
fixes #9369
  • Loading branch information
li6in9muyou committed Mar 10, 2023
1 parent 7e67738 commit 29ffc78
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
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: handle srcset attributes with newline after comma
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": []
}

0 comments on commit 29ffc78

Please sign in to comment.