Accept CSS numbers without a leading zero in rgb/rgba/hsl/hsla#187
Merged
Merged
Conversation
The numeric colour regexps used `\d+(\.\d+)?` which requires at least
one digit before the decimal point, so values like `rgba(0,0,0,.1)`
were not recognised as colours. Per CSS Values & Units, `<number>`
permits the integer part to be omitted (`[0-9]* '.' [0-9]+`).
The practical impact is that shorthand expansion silently dropped the
colour:
border: 1px solid rgba(0,0,0,.1)
-> border-top-width / -style are kept, border-top-color is gone.
background: url(x.png) rgba(0,0,0,.1)
-> background-image is kept, background-color is gone.
This bites users of Dart Sass + Premailer because Dart Sass's
`compressed` output strips leading zeros, so `.1` is what the
inliner actually receives.
Switching the integer-and-optional-fraction pattern to
`(?:\d*\.)?\d+` accepts `1`, `1.5`, and `.5` while still
rejecting a bare `1.` (also invalid per spec).
Tests cover both the regex itself (positive cases for `.1`-style
values) and the shorthand-expansion regression for `border:` and
`background:`.
Contributor
|
thx! 2.2.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.
RE_COLOUR_NUMERIC/RE_COLOUR_NUMERIC_ALPHAuse\d+(\.\d+)?for eachnumeric component, which requires at least one digit before the decimal
point. CSS Values & Units allows
<number>to omit the integer part(
[0-9]* '.' [0-9]+), so values likergba(0,0,0,.1)are not recognisedas colours.
The user-visible effect is that shorthand expansion silently drops the
colour. For example:
The same shorthand with
rgba(0,0,0,0.1)works correctly.background:is affected the same way (
background-coloris dropped).This bites Premailer users in the wild because Dart Sass's
compressedoutput strips leading zeros, so
.1is what the email inliner actuallyreceives.
This PR replaces
\d+(\.\d+)?with(?:\d*\.)?\d+in both numericcolour regexps. The new pattern accepts
1,1.5, and.5while stillrejecting bare
1.(also invalid per spec).Tests:
RE_COLOUR(.1-style alpha forrgba/hsla).border:andbackground:coveringrgba(0,0,0,.1).Pre-Merge Checklist