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: join srcset in source with ", " #7918

Merged
merged 6 commits into from Apr 11, 2022

Conversation

Shinyaigeek
Copy link
Contributor

↪️ Pull Request

Fixes: #7884

I found this is parcel’s issue. htmlnano depends on srcset, npm module to parse srcset attribute and after sindresorhus/srcset#11 PR was merged srcset module cannot parse srcset attribute without whitespace after “,” because hoge.png,bar.png is a valid URL.

However, parsel joins multiple image URLs in srcset attribute with “,” so this issue happens. parcel should join multiple image URLs in srcset attribute with “, “(with space), so I fixed so.

💻 Examples

<source srcset="hoge.png?as=webp&width=400, hoge.png?as=webp&width=800 2x">

into transformed into above by HTMLTransformer

<source srcset="hoge.HASH.png,hoge.HASH.png 2x">

but srcset module cannot parse this srcset attribute as a two image URLs.

🚨 Test instructions

I fixed html srcset integration testcase to check output HTML's srcset is valid.

✔️ PR Todo

  • Added/updated unit tests for this change
  • Filled out test instructions (In case there aren't any unit tests)
  • Included links to related issues/PRs

@mischnic
Copy link
Member

mischnic commented Apr 7, 2022

https://html.spec.whatwg.org/multipage/images.html#srcset-attribute:

If present, its value must consist of one or more image candidate strings, each separated from the next by a U+002C COMMA character (,). If an image candidate string contains no descriptors and no ASCII whitespace after the URL, the following image candidate string, if there is one, must begin with one or more ASCII whitespace.

@@ -96,7 +96,7 @@ function collectSrcSetDependencies(asset, srcset, opts) {
newSources.push(pair.join(' '));
}

return newSources.join(',');
return newSources.join(', ');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might be worth a comment explaining the significance of the trailing space

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for late response, b19e0af 👍

@mischnic mischnic merged commit fdeb508 into parcel-bundler:v2 Apr 11, 2022
@mischnic mischnic mentioned this pull request Dec 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

picture srcset missing space
4 participants