-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Validator] [CssColor] Fixed default behavior #43369
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
Conversation
private const PATTERN_RGB = '/^rgb\((0|255|25[0-4]|2[0-4]\d|1\d\d|0?\d?\d),\s*(0|255|25[0-4]|2[0-4]\d|1\d\d|0?\d?\d),\s*(0|255|25[0-4]|2[0-4]\d|1\d\d|0?\d?\d)\)$/i'; | ||
private const PATTERN_RGBA = '/^rgba\((0|255|25[0-4]|2[0-4]\d|1\d\d|0?\d?\d),\s*(0|255|25[0-4]|2[0-4]\d|1\d\d|0?\d?\d),\s*(0|255|25[0-4]|2[0-4]\d|1\d\d|0?\d?\d),\s*(0|0?\.\d|1(\.0)?)\)$/i'; | ||
private const PATTERN_HSL = '/^hsl\((0|360|35\d|3[0-4]\d|[12]\d\d|0?\d?\d),\s*(0|100|\d{1,2})%,\s*(0|100|\d{1,2})%\)$/i'; | ||
private const PATTERN_HSLA = '/^hsla\((0|360|35\d|3[0-4]\d|[12]\d\d|0?\d?\d),\s*(0|100|\d{1,2})%,\s*(0|100|\d{1,2})%,\s*(0?\.\d|1(\.0)?)\)$/i'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
modern browsers are making hsl
and hsla
aliases, meaning that hsl()
also supports the fourth argument. Should we use hsla?
here ?
Note that the same applies to rgb
and rgba
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As we are not sticky to the browser environment (for any reason we could need to validate strict hsla
from console app), I think we should leave as it is, and users who wants to validate HSL(A) could use both formats.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whether you run that validator in the console or in the webserver, you are never running it in a browser, so I don't understand your comment.
If you are confused about the usage of modern browsers
in my previous comment, replace it with modern CSS (supported in all modern browsers)
. The constraint is named CssColor
, so I guess it is still intended to be based on the CSS spec.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understood it by validating values which are going to be used in a browser. But ok, from the CSS point of view, hsl
and hsla
are aliases. The main problem if we merge hsl
and hsla
is to validate the mandatory usage of the 4th value if the a
is present, I don't know if we could make it done with regex.
8ac7153
to
038cb34
Compare
As mentioned on twitter, feel free to pick up some tweaks from my PR. I added some other edge cases and some tests too as the alpha canal value is never testes with numbers like Thanks for this new validator 🙂 |
038cb34
to
cac2ccf
Compare
Thank you @welcoMattic. |
Following the @javiereguiluz PR in docs (symfony/symfony-docs#15906), I figured out I've missed the default behavior of the constraint, which is "all formats are valid if you pass no arguments". It's fixed.
I've also replaced an overengineered
array_reduce
with animplode
.Tests have been updated too.