diff --git a/src/Symfony/Component/Validator/Constraints/EmailValidator.php b/src/Symfony/Component/Validator/Constraints/EmailValidator.php index d0eaa45402275..58b372d988dd5 100644 --- a/src/Symfony/Component/Validator/Constraints/EmailValidator.php +++ b/src/Symfony/Component/Validator/Constraints/EmailValidator.php @@ -51,6 +51,9 @@ public function validate($value, Constraint $constraint) } $value = (string) $value; + if ('' === $value) { + return; + } if (null === $constraint->strict) { $constraint->strict = $this->isStrict; diff --git a/src/Symfony/Component/Validator/Tests/Constraints/EmailValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/EmailValidatorTest.php index 344139a44f171..9299c7efad2e2 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/EmailValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/EmailValidatorTest.php @@ -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'); @@ -256,3 +263,11 @@ public function provideCheckTypes() ]; } } + +class EmptyEmailObject +{ + public function __toString() + { + return ''; + } +}
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: