Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 469d82d

Browse filesBrowse files
committed
bug #36672 [Validator] Skip validation when email is an empty object (acrobat)
This PR was merged into the 3.4 branch. Discussion ---------- [Validator] Skip validation when email is an empty object | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tickets | <!-- prefix each issue number with "Fix #", if any --> | License | MIT | Doc PR | <!-- required for new features --> When the value passed to the email validator is an empty object the validator is still called and will mark the value as invalid. The object should be skipped in this case, as it is also done in the `UrlValidator` https://github.com/symfony/symfony/blob/bfdbb244fe311008437e3634cc97fefae8cc7446/src/Symfony/Component/Validator/Constraints/UrlValidator.php#L59-L62 <!-- Replace this notice by a short README for your feature/bugfix. This will help people understand your PR and can be used as a start for the documentation. Additionally (see https://symfony.com/releases): - Always add tests and ensure they pass. - Never break backward compatibility (see https://symfony.com/bc). - Bug fixes must be submitted against the lowest maintained branch where they apply (lowest branches are regularly merged to upper ones so they get the fixes too.) - Features and deprecations must be submitted against branch master. --> Commits ------- de5d68e Skip validation when email is an empty object
2 parents e3d2a50 + de5d68e commit 469d82d
Copy full SHA for 469d82d

File tree

Expand file treeCollapse file tree

2 files changed

+18
-0
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+18
-0
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Constraints/EmailValidator.php
+3Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Tests/Constraints/EmailValidatorTest.php
+15Lines 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)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.