Skip to content

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

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
wants to merge 2 commits into from

Conversation

theofidry
Copy link
Contributor

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 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
    • NotBlank: already done
    • Blank: already done
    • NotNull: already done
    • IsNull: already done
    • [ ] IsTrue
    • [ ] IsFalse
    • [ ] Type
  • String Constraints¶
    • [ ] Email
    • 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

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

**Warning**: *null* and *blank* values are not handled by this constraint. To
handle them, refers to the :doc:`/reference/constraints/Null`,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo here: refer

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@xabbuh does this generic warning message is good for you? I would like to agree on the message in one place first before applying it everywhere needed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would write it like "null and the empty string are not handled by this constraint. Additionally add the NotBlank or NotNull constraint to exclude these values."

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and then we should add it in a caution block

@theofidry theofidry force-pushed the validator-blank-null branch from 869f904 to ef7976b Compare February 15, 2016 00:14
weaverryan added a commit that referenced this pull request 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~~
  - ~~[ ] 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
@weaverryan
Copy link
Member

Thanks @theofidry! I've made the final changes. And yes I believe this problem extends also to LessThan, LessThankOrEqual, etc. I haven't added the notes here - we can do that in another PR.

@weaverryan weaverryan closed this Sep 24, 2017
@theofidry theofidry deleted the validator-blank-null branch September 24, 2017 18:34
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.

3 participants