[vector_graphics_compiler] Fix HSL color parsing for decimal percentage components#11619
[vector_graphics_compiler] Fix HSL color parsing for decimal percentage components#11619fondoger wants to merge 2 commits intoflutter:mainfrom
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
There was a problem hiding this comment.
Code Review
This pull request updates the SVG parser to correctly handle HSL and HSLA color strings, specifically addressing issues with decimal percentages in lightness and decimal values in alpha channels. It changes the internal storage of color components to num to preserve precision during parsing and adds comprehensive tests for various HSL/HSLA formats. I have no feedback to provide.
…ge components Decimal percentage tokens in hsl()/hsla() were incorrectly multiplied by 2.55 (the rgb % → 0-255 factor), causing wrong saturation/lightness values (e.g. 76.27% → 194 instead of 76.27) and therefore wrong colors. Non-percentage alpha decimals (0–1) were also affected. Fix: track whether each token had a '%' suffix; for HSL percentage components return the raw float (0–100), and for unitless alpha decimals multiply by 255 instead of 2.55. Fixes: flutter/flutter#185833
a2a9d0f to
a835ab4
Compare
Description
Fixes a bug in the HSL color parser where decimal percentage components
(e.g.
76.2745098039%) were incorrectly multiplied by2.55— theconversion factor used for rgb percentages (percent → 0–255). For
hsl, saturation and lightness must stay in the 0–100 range (later
divided by 100) so the multiplication produced wildly wrong values
(e.g.
76.27 → 194, then194 / 100 = 1.94).The same branch also mis-handled the
hslaalpha component: a unitlessdecimal like
0.5should be converted to 0–255 via× 255, not× 2.55.Root cause
parser.dartcheckedrawColor.contains('.')and unconditionallyapplied
* 2.55, regardless of whether the current function wasrgb()/rgba()(correct) orhsl()/hsla()(incorrect).Fix
Track whether each token had a
%suffix before stripping it.For HSL percentage components, return the raw
double(0–100 range).For unitless alpha decimals (0–1 range), multiply by 255.
Reproduction (from issue #185833)
#efdeff❌#c286ff✓Tests
Four new tests added to
parsers_test.dart:hslwith integer percentages (regression)hslwith decimal lightness percentage (the reported bug)hslawith integer percentages + decimal alpha (regression)hslawith decimal lightness + decimal alpha (combined case)Related Issues
Fixes flutter/flutter#185833