From de5d68ef2a6defc2cfd68b5d7a91635bec81451d Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Sun, 3 May 2020 21:30:24 +0200 Subject: [PATCH] Skip validation when email is an empty object --- .../Validator/Constraints/EmailValidator.php | 3 +++ .../Tests/Constraints/EmailValidatorTest.php | 15 +++++++++++++++ 2 files changed, 18 insertions(+) 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 ''; + } +} pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

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:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy