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..a42cdda5dc880 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/EmailValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/EmailValidatorTest.php @@ -40,6 +40,16 @@ public function testEmptyStringIsValid() $this->assertNoViolation(); } + public function testObjectEmptyStringIsValid() + { + $this->validator->validate(new EmptyEmailObject(), new Email()); + + $this->assertNoViolation(); + } + + /** + * @expectedException \Symfony\Component\Validator\Exception\UnexpectedTypeException + */ public function testExpectsStringCompatibleType() { $this->expectException('Symfony\Component\Validator\Exception\UnexpectedTypeException'); @@ -256,3 +266,11 @@ public function provideCheckTypes() ]; } } + +class EmptyEmailObject +{ + public function __toString() + { + return ''; + } +}