Skip to content

Commit

Permalink
bug #23341 [DoctrineBridge][Security][Validator] do not validate empt…
Browse files Browse the repository at this point in the history
…y 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
-------

fd7ad23 do not validate empty values
  • Loading branch information
fabpot committed Jul 3, 2017
2 parents 4e65c1f + fd7ad23 commit 77d06b5
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
Expand Up @@ -62,6 +62,10 @@ public function validate($entity, Constraint $constraint)
throw new ConstraintDefinitionException('At least one field has to be specified.');
}

if (null === $entity) {
return;
}

if ($constraint->em) {
$em = $this->registry->getManager($constraint->em);

Expand Down
Expand Up @@ -39,6 +39,10 @@ public function validate($password, Constraint $constraint)
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\UserPassword');
}

if (null === $password || '' === $password) {
return;
}

$user = $this->tokenStorage->getToken()->getUser();

if (!$user instanceof UserInterface) {
Expand Down
Expand Up @@ -48,7 +48,7 @@ public function validate($value, Constraint $constraint)
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Url');
}

if (null === $value) {
if (null === $value || '' === $value) {
return;
}

Expand Down

0 comments on commit 77d06b5

Please sign in to comment.