-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Validator] Allow empty string on LengthValidator #45993
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
Hey! I see that this is your first PR. That is great! Welcome! Symfony has a contribution guide which I suggest you to read. In short:
Review the GitHub status checks of your pull request and try to solve the reported issues. If some tests are failing, try to see if they are failing because of this change. When two Symfony core team members approve this change, it will be merged and you will become an official Symfony contributor! I am going to sit back now and wait for the reviews. Cheers! Carsonbot |
9c07484
to
ab67e21
Compare
I just looked at the ticket but: there are about thirty validators that authorize an empty string? Why a different behavior for this one? |
Allow empty string to match documentation "As with most of the other constraints, null and empty strings are considered valid values".
4afe14e
to
07f30ec
Compare
This decision was made in #31528 because the semantic of Also, the DX for a nullable string property requiring at least 1 char (hence reject empty strings) — which is a common use-case for clean data types — was bad, requiring to write: #[Length(min: 1)] <- was actually completely useless and unintuitive, since it was allowing empty strings despite min: 1
#[NotBlank(allowNull: true)] <- was too indirect to express empty strings are not allowed but the property is nullable If you really wish to allow empty strings, you can use: #[AtLeastOneOf([
new Length(0),
new Length(min: 6),
])] which would be explicit about this use-case. |
Closing as explained. Thanks for asking and the answers :) |
…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
Allow empty string to match documentation "As with most of the other constraints, null and empty strings are considered valid values".