Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[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

Merged
merged 1 commit into from
Jul 3, 2019
Merged

[Validator] Add a Length::$allowEmptyString option to reject empty strings #31528

merged 1 commit into from
Jul 3, 2019

Conversation

ogizanagi
Copy link
Contributor

@ogizanagi ogizanagi commented May 17, 2019

Q A
Branch? 4.4
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? yes
Tests pass? yes
Fixed tickets N/A
License MIT
Doc PR Todo (change the warning on top of https://symfony.com/doc/current/reference/constraints/Length.html)

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.

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.

@ogizanagi
Copy link
Contributor Author

Status: Needs work

to only account when a min (or value, i.e min & max) value is set.

Copy link
Contributor Author

@ogizanagi ogizanagi left a 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] : [];
Copy link
Contributor Author

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.

@ogizanagi ogizanagi changed the base branch from master to 4.4 May 28, 2019 16:38
@ogizanagi
Copy link
Contributor Author

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.
@ogizanagi ogizanagi requested a review from fabpot July 1, 2019 08:00
@fabpot
Copy link
Member

fabpot commented Jul 3, 2019

Thank you @ogizanagi.

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