Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[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

Merged
merged 1 commit into from
Oct 12, 2021

Conversation

welcoMattic
Copy link
Member

Q A
Branch? 5.4
Bug fix? no
New feature? no
Deprecations? no
Tickets
License MIT
Doc PR symfony/symfony-docs#...

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 an implode.

Tests have been updated too.

src/Symfony/Component/Validator/Constraints/CssColor.php Outdated Show resolved Hide resolved
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';
Copy link
Member

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

Copy link
Member Author

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.

Copy link
Member

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.

Copy link
Member Author

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.

@welcoMattic welcoMattic force-pushed the hexadecimal-constraint branch from 8ac7153 to 038cb34 Compare October 8, 2021 12:41
@flohw
Copy link
Contributor

flohw commented Oct 8, 2021

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 .3 😉

Thanks for this new validator 🙂

@carsonbot carsonbot changed the title [Valdiator] [CssColor] Fixed default behavior [Validator] [Valdiator] [CssColor] Fixed default behavior Oct 8, 2021
@javiereguiluz javiereguiluz changed the title [Validator] [Valdiator] [CssColor] Fixed default behavior [Validator] [CssColor] Fixed default behavior Oct 8, 2021
@welcoMattic welcoMattic force-pushed the hexadecimal-constraint branch from 038cb34 to cac2ccf Compare October 8, 2021 12:58
@fabpot
Copy link
Member

fabpot commented Oct 12, 2021

Thank you @welcoMattic.

@fabpot fabpot merged commit 83c699b into symfony:5.4 Oct 12, 2021
@welcoMattic welcoMattic deleted the hexadecimal-constraint branch November 10, 2021 08:34
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.

6 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.