Fix parsing of srcset without whitespaces#11
Merged
sindresorhus merged 4 commits intosindresorhus:mainfrom Apr 19, 2021
Merged
Conversation
352fc47 to
4913176
Compare
sindresorhus
requested changes
Apr 18, 2021
index.js
Outdated
| 'use strict'; | ||
|
|
||
| const integerRegex = /^-?\d+$/; | ||
| const srcsetRegex = /\s*([^,]\S*[^,](?:\s+[^,]+)?)\s*(?:,|$)/; |
Owner
There was a problem hiding this comment.
Why such a complicated regex? If it really has to be like this, I would like to see a code comment that explains it.
Contributor
Author
There was a problem hiding this comment.
I renamed the regex to imageCandidateRegex to indicate that it matches loosely to an "image candidate string". It's the simplest way I can think of for now to solve the issue where there's no whitespace between two image candidate strings. I've included some comments above. Let me know if I can make it clearer!
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
srcset without whitespaces like
banner-HD.jpeg 2x,banner-HD.jpeg 2x,banner-HD.jpeg 2x,banner-phone.jpeg 100w,http://site.com/image.jpg?foo=100w,lorem 1xcannot be parsed. I rewrote the split logic and refactor the code to match more closely to the spec. Below are some added rules:1xdescriptor.Also added some tests.