Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
carsonbot commentedApr 11, 2022
Hey! I see that this is your first PR. That is great! Welcome! Symfony has acontribution 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 |
nicolas-grekas commentedApr 11, 2022
neufman commentedApr 11, 2022
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".
ogizanagi commentedApr 11, 2022 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
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 uselessand 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([newLength(0),newLength(min:6),])] which would be explicit about this use-case. |
nicolas-grekas commentedApr 12, 2022
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 DocsEmpty strings are no longer valid if a min is passed, null values stillvalidate.Changed in 6.0 along with dropping the deprecated `allowEmptyString`symfony/symfony#36818 option. There is some discussion that this is the intended behavior insymfony/symfony#45993Commits-------9fa967e Update Length Validator Empty String Docs
Uh oh!
There was an error while loading.Please reload this page.
Allow empty string to match documentation "As with most of the other constraints, null and empty strings are considered valid values".