8000 Skip validation when email is an empty object · symfony/symfony@de5d68e · GitHub
[go: up one dir, main page]

Skip to content

Commit de5d68e

Browse files
committed
Skip validation when email is an empty object
1 parent bfdbb24 commit de5d68e

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/Symfony/Component/Validator/Constraints/EmailValidator.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ public function validate($value, Constraint $constraint)
5151
}
5252

5353
$value = (string) $value;
54+
if ('' === $value) {
55+
return;
56+
}
5457

5558
if (null === $constraint->strict) {
5659
$constraint->strict = $this->isStrict;

src/Symfony/Component/Validator/Tests/Constraints/EmailValidatorTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@ public function testEmptyStringIsValid()
4040
$this->assertNoViolation();
4141
}
4242

43+
public function testObjectEmptyStringIsValid()
44+
{
45+
$this->validator->validate(new EmptyEmailObject(), new Email());
46+
47+
$this->assertNoViolation();
48+
}
49+
4350
public function testExpectsStringCompatibleType()
4451
{
4552
$this->expectException('Symfony\Component\Validator\Exception\UnexpectedTypeException');
@@ -256,3 +263,11 @@ public function provideCheckTypes()
256263
];
257264
}
258265
}
266+
267+
class EmptyEmailObject
268+
{
269+
public function __toString()
270+
{
271+
return '';
272+
}
273+
}

0 commit comments

Comments
 (0)
0