Skip to content

[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

Merged
merged 1 commit into from
Jan 29, 2019

Conversation

dunglas
Copy link
Member

@dunglas dunglas commented Dec 18, 2018

Q A
Branch? master
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
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.

@nicolas-grekas nicolas-grekas added this to the next milestone Dec 19, 2018
@nicolas-grekas
Copy link
Member

ping @dunglas

@dunglas dunglas force-pushed the notblank_allow_null branch from aea586d to 5856f27 Compare January 27, 2019 18:30
@dunglas
Copy link
Member Author

dunglas commented Jan 27, 2019

Should be ready now

Copy link
Member

@xabbuh xabbuh left a 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?

@dunglas dunglas force-pushed the notblank_allow_null branch from 913261c to 9b72462 Compare January 29, 2019 06:18
@fabpot fabpot force-pushed the notblank_allow_null branch from 9b72462 to 484d22a Compare January 29, 2019 06:35
@fabpot
Copy link
Member

fabpot commented Jan 29, 2019

Thank you @dunglas.

@fabpot fabpot merged commit 484d22a into symfony:master Jan 29, 2019
fabpot added a commit that referenced this pull request Jan 29, 2019
…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
@javiereguiluz
Copy link
Member

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!

@dunglas
Copy link
Member Author

dunglas commented Feb 1, 2019

Sorry about that @javiereguiluz.

@dunglas dunglas deleted the notblank_allow_null branch February 1, 2019 10:22
javiereguiluz added a commit to symfony/symfony-docs that referenced this pull request Feb 1, 2019
…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
@nicolas-grekas nicolas-grekas modified the milestones: next, 4.3 Apr 30, 2019
@fabpot fabpot mentioned this pull request May 9, 2019
fabpot added a commit that referenced this pull request Jul 3, 2019
…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
@typomedia
Copy link

👍 @fabpot pls. merge this option to Symfony 3.4 🙌

@xabbuh
Copy link
Member

xabbuh commented Oct 11, 2019

@typomedia New features are never added in patch releases.

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.

9 participants