-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Validator] NotBlank: add a new option to allow null values #29641
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
src/Symfony/Component/Validator/Tests/Constraints/NotBlankValidatorTest.php
Outdated
Show resolved
Hide resolved
ping @dunglas |
aea586d
to
5856f27
Compare
Should be ready now |
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.
Can you please also add an entry to the changelog?
913261c
to
9b72462
Compare
9b72462
to
484d22a
Compare
Thank you @dunglas. |
…alues (dunglas) This PR was squashed before being merged into the 4.3-dev branch (closes #29641). Discussion ---------- [Validator] NotBlank: add a new option to allow null values | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes <!-- don't forget to update src/**/CHANGELOG.md files --> | BC breaks? | no <!-- see https://symfony.com/bc --> | Deprecations? | no <!-- don't forget to update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tests pass? | yes <!-- please add some, will be required by reviewers --> | Fixed tickets | #27876 | License | MIT | Doc PR | todo This PR adds a new option to the `@NotBlank` constraint to allow null values. As described in #27876, this is particularly useful when creating web APIs. Commits ------- 484d22a [Validator] NotBlank: add a new option to allow null values
I've created symfony/symfony-docs#10954 to document this new feature. @dunglas please always remember to create at least an issue in Symfony Docs to not forget about documenting new features. Thanks! |
Sorry about that @javiereguiluz. |
…aviereguiluz) This PR was merged into the master branch. Discussion ---------- Document the allowNull option for NotBlank constraint This documents symfony/symfony#29641 Commits ------- ab2c4f1 Document the allowNull option for NotBlank constraint
…reject empty strings (ogizanagi) This PR was merged into the 4.4 branch. Discussion ---------- [Validator] Add a Length::$allowEmptyString option to reject empty strings | Q | A | ------------- | --- | Branch? | 4.4 <!-- see below --> | Bug fix? | no | New feature? | yes <!-- please update src/**/CHANGELOG.md files --> | BC breaks? | no <!-- see https://symfony.com/bc --> | Deprecations? | yes <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tests pass? | yes <!-- please add some, will be required by reviewers --> | Fixed tickets | N/A <!-- #-prefixed issue number(s), if any --> | 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. Commits ------- e113e7f [Validator] Add a Length::$allowEmptyString option to reject empty strings
👍 @fabpot pls. merge this option to Symfony 3.4 🙌 |
@typomedia New features are never added in patch releases. |
This PR adds a new option to the
@NotBlank
constraint to allow null values. As described in #27876, this is particularly useful when creating web APIs.