Skip to content
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] deprecate the "allowEmptyString" option #36818

Merged
merged 1 commit into from
May 22, 2020

Conversation

xabbuh
Copy link
Member

@xabbuh xabbuh commented May 15, 2020

Q A
Branch? master
Bug fix? no
New feature? no
Deprecations? yes
Tickets Fix #36812
License MIT
Doc PR

@derrabus
Copy link
Member

Can we deprecate the allowEmptyString option instead? If someone wanted to disallow empty strings, they could use the NotBlank validator instead, or am I missing something?

@xabbuh xabbuh changed the title [Validator] deprecate disallowing empty strings with minimum lengths [Validator] deprecate the "allowEmptyString" option May 20, 2020
@xabbuh
Copy link
Member Author

xabbuh commented May 20, 2020

Good idea, this was actually suggested when the option was introduced in 4.4 (see #31528):

In my opinion, the flag could even be removed later.

@xabbuh xabbuh force-pushed the issue-36812 branch 4 times, most recently from 6df1211 to fbbde1e Compare May 21, 2020 08:53
@xabbuh xabbuh force-pushed the issue-36812 branch 2 times, most recently from 7f518d4 to a95b7a3 Compare May 22, 2020 13:22
@fabpot
Copy link
Member

fabpot commented May 22, 2020

Thank you @xabbuh.

@fabpot fabpot merged commit e00017e into symfony:master May 22, 2020
@xabbuh xabbuh deleted the issue-36812 branch May 22, 2020 17:11
@nicolas-grekas nicolas-grekas modified the milestones: next, 5.2 Oct 5, 2020
@fabpot fabpot mentioned this pull request Oct 5, 2020
@xosofox
Copy link
Contributor

xosofox commented Jul 28, 2021

Just wondering how we can achieve the "old behaviour" now when combining min, max and allowEmptyString=true

It used to be "ok" to have have either an empty string OR apply min-max-constraints - this is gone now. Or am I missing something?

@xabbuh
Copy link
Member Author

xabbuh commented Jul 28, 2021

Precisely for such use cases you can combine the Length constraint with other constraints using AtLeastOne (see the example in the upgrade guide): https://symfony.com/doc/current/reference/constraints/AtLeastOneOf.html

javiereguiluz added a commit to symfony/symfony-docs that referenced this pull request Apr 29, 2022
…rjohnson)

This PR was merged into the 6.0 branch.

Discussion
----------

[Validator] Update Length Validator Empty String Docs

Empty strings are no longer valid if a min is passed, null values still
validate.

Changed in 6.0 along with dropping the deprecated `allowEmptyString` symfony/symfony#36818 option. There is some discussion that this is the intended behavior in symfony/symfony#45993

Commits
-------

9fa967e Update Length Validator Empty String Docs
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.

[Validator] LengthValidator: allowEmptyString option set to false allows empty strings
7 participants