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

Skip to content

Commit 6136c94

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

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-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: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,16 @@ 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+
50+
/**
51+
* @expectedException \Symfony\Component\Validator\Exception\UnexpectedTypeException
52+
*/
4353
public function testExpectsStringCompatibleType()
4454
{
4555
$this->expectException('Symfony\Component\Validator\Exception\UnexpectedTypeException');
@@ -256,3 +266,11 @@ public function provideCheckTypes()
256266
];
257267
}
258268
}
269+
270+
class EmptyEmailObject
271+
{
272+
public function __toString()
273+
{
274+
return '';
275+
}
276+
}

0 commit comments

Comments
 (0)
0