Skip to content

Commit

Permalink
bug #36672 [Validator] Skip validation when email is an empty object …
Browse files Browse the repository at this point in the history
…(acrobat)

This PR was merged into the 3.4 branch.

Discussion
----------

[Validator] Skip validation when email is an empty object

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | yes
| New feature?  | no <!-- please update src/**/CHANGELOG.md files -->
| Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tickets       | <!-- prefix each issue number with "Fix #", if any -->
| License       | MIT
| Doc PR        | <!-- required for new features -->

When the value passed to the email validator is an empty object the validator is still called and will mark the value as invalid. The object should be skipped in this case, as it is also done in the `UrlValidator`

https://github.com/symfony/symfony/blob/bfdbb244fe311008437e3634cc97fefae8cc7446/src/Symfony/Component/Validator/Constraints/UrlValidator.php#L59-L62

<!--
Replace this notice by a short README for your feature/bugfix. This will help people
understand your PR and can be used as a start for the documentation.

Additionally (see https://symfony.com/releases):
 - Always add tests and ensure they pass.
 - Never break backward compatibility (see https://symfony.com/bc).
 - Bug fixes must be submitted against the lowest maintained branch where they apply
   (lowest branches are regularly merged to upper ones so they get the fixes too.)
 - Features and deprecations must be submitted against branch master.
-->

Commits
-------

de5d68e Skip validation when email is an empty object
  • Loading branch information
fabpot committed May 4, 2020
2 parents e3d2a50 + de5d68e commit 469d82d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
Expand Up @@ -51,6 +51,9 @@ public function validate($value, Constraint $constraint)
}

$value = (string) $value;
if ('' === $value) {
return;
}

if (null === $constraint->strict) {
$constraint->strict = $this->isStrict;
Expand Down
Expand Up @@ -40,6 +40,13 @@ public function testEmptyStringIsValid()
$this->assertNoViolation();
}

public function testObjectEmptyStringIsValid()
{
$this->validator->validate(new EmptyEmailObject(), new Email());

$this->assertNoViolation();
}

public function testExpectsStringCompatibleType()
{
$this->expectException('Symfony\Component\Validator\Exception\UnexpectedTypeException');
Expand Down Expand Up @@ -256,3 +263,11 @@ public function provideCheckTypes()
];
}
}

class EmptyEmailObject
{
public function __toString()
{
return '';
}
}

0 comments on commit 469d82d

Please sign in to comment.