Fix parsing space-less media-features#141
Merged
Merged
Conversation
Previously, `@media (width: 500px)` would be successfully parsed, but not `@media(width: 500px)` - it would tokenize to `@media(width:` and then get discarded. Fixes premailer#139
jdelStrother
commented
Aug 30, 2023
Comment on lines
+394
to
404
| # special-case the ( and ) tokens to remove inner-whitespace | ||
| # (eg we'd prefer '(width: 500px)' to '( width: 500px )' ) | ||
| case token | ||
| when '(' | ||
| current_media_query << token | ||
| when ')' | ||
| current_media_query.sub!(/ ?$/, token) | ||
| else | ||
| current_media_query << token << ' ' | ||
| end | ||
| end |
Contributor
Author
There was a problem hiding this comment.
This isn't necessary to fix the bug, but does give nicer media query names. It could be skipped if we're happy with
@media(min-width: 500px) {...}getting re-written to
@media ( min-width: 500px ) {...}I'm happy with either, but it's maybe not worth the extra complexity. Without it, I thought the test suite needing the extra spaces in, eg, @cp.find_by_selector('body', :'( min-width: 500px )') was kind of ugly... but I don't know how much real-world usage the media_types argument to find_selector is getting.
grosser
approved these changes
Sep 1, 2023
grosser
left a comment
Contributor
There was a problem hiding this comment.
looks a bit ugly, but the test-case is nice 👍
Contributor
|
1.16.0 |
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.
Previously,
@media (width:500px)would be successfully parsed, but not@media(width:500px)- it would result in@media(width:500px)as a single token, effectively ignoring themedia:500pxmedia-feature and assigning all the rules in that media query to the:allnamespace.This tokenizes
(and)separately ... which naively seems ok to me and passes all the tests, but I'd confess to being a little nervous how it behaves with real-world CSS.Fixes #139
Pre-Merge Checklist