Skip to content

Conversation

@controlol
Copy link
Contributor

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

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

@codecov
Copy link

codecov bot commented Dec 14, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

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              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@rubiin rubiin requested a review from pano9000 December 27, 2023 15:21
rubiin
rubiin previously approved these changes Dec 27, 2023
@WikiRik
Copy link
Member

WikiRik commented Jan 1, 2024

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?

@controlol
Copy link
Contributor Author

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.

WikiRik
WikiRik previously approved these changes Mar 15, 2024
@controlol
Copy link
Contributor Author

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.

@WikiRik WikiRik dismissed stale reviews from rubiin and themself via 690528d March 26, 2025 21:35
@WikiRik WikiRik requested a review from rubiin March 26, 2025 21:35
@rubiin rubiin merged commit a18d57d into validatorjs:master Mar 27, 2025
2 of 10 checks passed
@WikiRik
Copy link
Member

WikiRik commented Mar 27, 2025

@rubiin it seems we have merged this with a failing test. I'll fix this later today or tomorrow

@WikiRik
Copy link
Member

WikiRik commented Mar 27, 2025

Fixed in #2538

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants