validator.js icon indicating copy to clipboard operation
validator.js copied to clipboard

feat(isRgbColor) Allow second digit in rgba alpha value

Open controlol opened this issue 1 year ago • 4 comments

Updated the RegExp to allow a secondary digit for the alpha value when checking a rgba color. Added required tests and test the number of digits for the rgbaColorPercent RegExp.

References Modern browsers support multiple decimals for the alpha value in rgba() color values. This is also allowed in the CSS standard: https://www.w3.org/TR/css-color-3/#transparency

Checklist

  • [x] PR contains only changes related; no stray files, etc.
  • [x] README updated (where applicable)
  • [x] Tests written (where applicable)
  • [x] References provided in PR (where applicable)

controlol avatar Dec 14 '23 17:12 controlol

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Comparison is base (b958bd7) 99.95% compared to head (42ddf04) 99.95%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2346      +/-   ##
==========================================
- Coverage   99.95%   99.95%   -0.01%     
==========================================
  Files         107      107              
  Lines        2454     2449       -5     
  Branches      619      619              
==========================================
- Hits         2453     2448       -5     
  Partials        1        1              

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov[bot] avatar Dec 14 '23 17:12 codecov[bot]

I'm having a bit of trouble figuring out how many digits are allowed in the alpha value. Do you have any resources for that?

WikiRik avatar Jan 01 '24 21:01 WikiRik

This post suggests that the color is 32 bit and therefor 8 bits available for transparency (256 possibilities). So 1/256 has a precision of approximately 0.004 or 0.4%.

Unfortunately, the W3C page linked in the original pr does not state how many digits can be used. Many browsers also support rgba values in hexadecimal notation, although this is not part of the CSS3 standard.

controlol avatar Jan 04 '24 15:01 controlol

I just checked the PR by marcopixel. If this validation was intented for use with CSS I would change the current commit to use 0?\.\d+ instead of 0?\.\d{1,2}. Also checks should be added without a number after the dot.

controlol avatar May 22 '24 19:05 controlol