Skip to content

Commit

Permalink
fix: address srcset parsing with multiple spaces (#512)
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinBeckwith authored Jul 11, 2022
1 parent 15687a1 commit fefb5b6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/links.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,13 @@ function isAbsoluteUrl(url: string): boolean {

function parseAttr(name: string, value: string): string[] {
switch (name) {
case 'srcset':
return parseSrcset(value).map(p => p.url);
case 'srcset': {
// The swapping of any multiple spaces into a single space is here to
// work around this bug:
// https://github.com/sindresorhus/srcset/issues/14
const strippedValue = value.replace(/\s+/, ' ');
return parseSrcset(strippedValue).map(p => p.url);
}
default:
return [value];
}
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/srcset/index.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<html>
<body>
<img srcset="_site/foo.html, _site/bar.html"></img>
<img srcset="_site/foo.html, _site/bar.html"></img>
</body>
</html>

0 comments on commit fefb5b6

Please sign in to comment.