bug #23341 [DoctrineBridge][Security][Validator] do not validate empty values (xabbuh)
This PR was merged into the 2.7 branch.
Discussion
----------
[DoctrineBridge][Security][Validator] do not validate empty values
| Q | A
| ------------- | ---
| Branch? | 2.7
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | #23319
| License | MIT
| Doc PR |
Nearly all validators operating on scalar values (except for some special constraints) do ignore empty values. If you want to forbid them, you have to use the `NotBlank` constraint instead.
Commits
-------
fd7ad234bc
do not validate empty values
This commit is contained in:
commit
77d06b5d39
@ -62,6 +62,10 @@ class UniqueEntityValidator extends ConstraintValidator
|
||||
throw new ConstraintDefinitionException('At least one field has to be specified.');
|
||||
}
|
||||
|
||||
if (null === $entity) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($constraint->em) {
|
||||
$em = $this->registry->getManager($constraint->em);
|
||||
|
||||
|
@ -39,6 +39,10 @@ class UserPasswordValidator extends ConstraintValidator
|
||||
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\UserPassword');
|
||||
}
|
||||
|
||||
if (null === $password || '' === $password) {
|
||||
return;
|
||||
}
|
||||
|
||||
$user = $this->tokenStorage->getToken()->getUser();
|
||||
|
||||
if (!$user instanceof UserInterface) {
|
||||
|
@ -48,7 +48,7 @@ class UrlValidator extends ConstraintValidator
|
||||
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Url');
|
||||
}
|
||||
|
||||
if (null === $value) {
|
||||
if (null === $value || '' === $value) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user