-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Validator] Add a Length::$allowEmptyString option to reject empty strings #31528
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
[Validator] Add a Length::$allowEmptyString option to reject empty strings #31528
Conversation
Status: Needs work to only account when a |
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.
Status: Needs Review
|
||
public static function loadValidatorMetadata(ClassMetadata $metadata): void | ||
{ | ||
$allowEmptyString = property_exists(Assert\Length::class, 'allowEmptyString') ? ['allowEmptyString' => true] : []; |
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.
Trying to keep compatibility with lowest symfony/validator
versions for this bridge, as the code isn't impacted, only the tests fixtures are.
Same for the Form component.
Rebased & comments fixed Status: Needs Review |
…rings which defaults to `true` in 4.4 but will trigger a deprecation if not set explicitly in order to make the default `false` in 5.0.
Thank you @ogizanagi. |
which defaults to
true
in 4.4 but will trigger a deprecation if not set explicitlyin order to make the default
false
in 5.0.While it could be solved now thanks to #29641 by using both
@Length(min=1)
&@NotBlank(allowNull=true)
constraints,as expressed in #27876 (comment) and following comments, the
@Length(min=1)
behavior doesn't match our expectations when reading it: it feels logical to invalidate empty strings, but it actually doesn't.Hence the proposal of making the behavior of rejecting empty strings the default in 5.0.
In my opinion, the flag could even be removed later.