8000 [Validators] Assert Length min value does not work on null · Issue #16157 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Validators] Assert Length min value does not work on null #16157

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

Closed
theofidry opened this issue Oct 6, 2015 · 7 comments
Closed

[Validators] Assert Length min value does not work on null #16157

theofidry opened this issue Oct 6, 2015 · 7 comments

Comments

@theofidry
Copy link
Contributor

According to the documentation:

Validates that a given string length is between some minimum and maximum value.

If the validated property has a null value or is an empty string, specifying a min value won't generate any violations. Tested on PHP5.6 with Symfony2.7.

@unkind
Copy link
Contributor
unkind commented Oct 6, 2015

It is important to notice that NULL values and empty strings are considered valid no matter if the constraint required a minimum length. Validators are triggered only if the value is not blank.

Empty strings are weird case though.

@Tobion
Copy link
Contributor
Tobion commented Oct 6, 2015

All validators accept null and empty string. There are already alot of issues about this topic with further information.

@Tobion Tobion closed this as completed Oct 6, 2015
@theofidry
Copy link
Contributor Author

If you specify a constraint "my property must be a string of at least 2 characters", you expect a violation to be raised for a null or empty string no matter how you look at it it's just weird. But if it's considered as the expected behaviour, fine, but put a word on it in the doc. So please the ticket @Tobion.

@theofidry
Copy link
Contributor Author

My bad, didn't see your message @unkind, where is this message quoted from? Can't find it T.T

@jakzal
Copy link
Contributor
jakzal commented Oct 14, 2015

@theofidry it's a quote from the documentation you referenced: http://symfony.com/doc/current/reference/constraints/Length.html#min

@theofidry
Copy link
Contributor Author

Indeed I've found it later sorry about that, thanks @jakzal. But I still believe this should put a warning under the head title though.

8000

@jakzal
Copy link
Contributor
jakzal commented Oct 14, 2015

@theofidry agreed. Could you send a PR to symfony/symfony-docs?

weaverryan added a commit to symfony/symfony-docs that referenced this issue Sep 24, 2017
…um string length (theofidry)

This PR was submitted for the 2.3 branch but it was merged into the 2.7 branch instead (closes #6270).

Discussion
----------

[Validator] Add warning for null and blank values for minimum string length

| Q | A |
| --- | --- |
| Doc fix? | yes |
| New docs? | no |
| Applies to | 2.3+ |
| Fixed tickets | symfony/symfony#16157 |

Follow up of #5789.

Summary of what has been said: even though the [Length#min](http://symfony.com/doc/current/reference/constraints/Length.html#min) option is well detailed and mention the case of `null` values, the introduction is still confusing:

> Validates that a given string length is between some minimum and maximum value.

As a result, a warning note is being added under this introduction.

I've listed all the Symfony constraints. For some this `null` and `blank` values specificity has already been mentioned. I've noted the ones on which this warning does not apply, but for some I am not sure so it needs to be doubled checked.
- Basic Contraints
  - [x] NotBlank: already done
  - [x] Blank: already done
  - [x] NotNull: already done
  - [x] IsNull: already done
  - ~~[ ] IsTrue~~
  - ~~[ ] IsFalse~~
  - ~~
53A8
[ ] Type~~
- String Constraints¶
  - ~~[ ] Email~~
  - [x] Length
  - ~~[ ] Url~~
  - ~~[ ] Regex~~
  - ~~[ ] Ip~~
  - ~~[ ] Uuid~~
- Number Constraints¶
  - [ ] Range
- Comparison Constraints¶
  - ~~[ ] EqualTo~~
  - ~~[ ] NotEqualTo~~
  - ~~[ ] IdenticalTo~~
  - ~~[ ] NotIdenticalTo~~
  - [ ] LessThan: needed? How `@Assert\LessThan("-18 years")` behaves if the value is null?
  - [ ] LessThanOrEqual: same as `LessThan`
  - [ ] GreaterThan: same as `LessThan`
  - [ ] GreaterThanOrEqual: same as `LessThan`
- Date Constraints¶
  - ~~[ ] Date~~
  - ~~[ ] DateTime~~
  - ~~[ ] Time~~
- Collection Constraints¶
  - ~~[ ] Choice~~
  - ~~[ ] Collection~~
  - ~~[ ] Count~~
  - ~~[ ] UniqueEntity~~
  - ~~[ ] Language~~
  - ~~[ ] Locale~~
  - ~~[ ] Country~~
- File Constraints¶
  - ~~[ ] File~~
  - ~~[ ] Image~~
- Financial and other Number Constraints¶
  - ~~[ ] Bic~~
  - ~~[ ] CardScheme~~
  - ~~[ ] Currency~~
  - ~~[ ] Luhn~~
  - ~~[ ] Iban~~
  - ~~[ ] Isbn~~
  - ~~[ ] Issn~~
- Other Constraints¶
  - ~~[ ] Callback~~
  - ~~[ ] Expression~~
  - ~~[ ] All~~
  - ~~[ ] UserPassword~~
  - ~~[ ] Valid~~

Commits
-------

38d44c2 [Validator] Add warning for null and blank values for minimum string length
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants
0