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(postcss-colormin): prevent interpreting all numbers as hex colors. #1118

Closed
wants to merge 2 commits into from

Conversation

ludofischer
Copy link
Collaborator

The issue is that the colord parser is so lenient it accepts single numbers
as hex colors.

Fix #1113, fix #1115

@ludofischer
Copy link
Collaborator Author

@omgovich do you agree with this solution? I wonder if the colord parser is not a bit too lenient. The interesting part is that the cssnano code never checks if color can be at that position, I guess because it is a bit complicated with all the shorthand declarations, so it relies on the color library failing to parse to decide whether to continue or not. Because colord accepts more values than color, cssnano ends up transforming any number with three digits.

@michaelfaith
Copy link

Thanks for the quick turnaround on this.

@omgovich
Copy link
Contributor

omgovich commented May 20, 2021

Hey guys. Sad to see these issues.

Colord was created to help people to type a color values (for example, in color picker fields) and fix possible mistakes there. It produces valid CSS colors, but parses even broken ones. I've never aimed to handle any other input except possible color value before.

The current workaround is good enought I guess.
I'll try to find a more elegant solution for cssnano soon. Maybe implement some strict option to make the parser follow CSS specs.

@ludofischer
Copy link
Collaborator Author

We could use more readable integration test. The regression was visible in the generated output, and I even looked at it, but because the result is a single minified string, it is very easy to miss details. Maybe we should also run one plugin at a time on the sample CSS.

The issue is that the colord parser is so lenient it accepts single numbers
as hex colors.

Fix #1113, fix #1115
@codecov-commenter
Copy link

codecov-commenter commented May 20, 2021

Codecov Report

Merging #1118 (9684747) into master (8a31ca3) will increase coverage by 0.00%.
The diff coverage is 100.00%.

❗ Current head 9684747 differs from pull request most recent head 59d545b. Consider uploading reports for the commit 59d545b to get more accurate results
Impacted file tree graph

@@           Coverage Diff           @@
##           master    #1118   +/-   ##
=======================================
  Coverage   96.37%   96.37%           
=======================================
  Files         115      115           
  Lines        3582     3585    +3     
  Branches     1054     1056    +2     
=======================================
+ Hits         3452     3455    +3     
  Misses        121      121           
  Partials        9        9           
Impacted Files Coverage Δ
packages/postcss-colormin/src/colours.js 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8a31ca3...59d545b. Read the comment docs.

@omgovich
Copy link
Contributor

Already working on strict mode implementation for Colord.
Hope I'll release an update tomorrow and we'll be able to get rid of the workarounds and hacks.

@alexander-akait
Copy link
Member

@ludofischer Do you think we should merge this and do fast release or better to migrate on v2 in other PR?

@ludofischer
Copy link
Collaborator Author

ludofischer commented May 21, 2021 via email

@michaelfaith
Copy link

Just to get a sense for timing, any thoughts when this might make it into a release? Just trying to guage whether or not i should use a workaround or wait for the fix.

@omgovich
Copy link
Contributor

omgovich commented May 21, 2021

Colord v2 is released and PR that fixes everything is ready to merge #1122

@ludofischer
Copy link
Collaborator Author

Superseded by #1122

cssnano 5.0.4 with fixed color parsing is out, please give it a try.

@ludofischer ludofischer deleted the fix-colormin branch May 21, 2021 18:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants