diff --git a/src/Symfony/Component/Validator/Constraints/EmailValidator.php b/src/Symfony/Component/Validator/Constraints/EmailValidator.php index 8a8aadea4692b..928895829231e 100644 --- a/src/Symfony/Component/Validator/Constraints/EmailValidator.php +++ b/src/Symfony/Component/Validator/Constraints/EmailValidator.php @@ -93,7 +93,7 @@ public function validate($value, Constraint $constraint) return; } - $host = substr($value, strpos($value, '@') + 1); + $host = substr(strrchr($value, '@'), 1); // Check for host DNS resource records if ($constraint->checkMX) { diff --git a/src/Symfony/Component/Validator/Tests/Constraints/EmailValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/EmailValidatorTest.php index c0dab3d70639b..9b6b1b7f35eed 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/EmailValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/EmailValidatorTest.php @@ -69,6 +69,7 @@ public function getValidEmails() array('fabien@symfony.com'), array('example@example.co.uk'), array('fabien_potencier@example.fr'), + array('"very@uncommon"@example.com'), ); } @@ -143,4 +144,19 @@ public function getDnsChecks() array('AAAA', Email::HOST_CHECK_FAILED_ERROR), ); } + + public function testHostnameIsProperlyParsed() + { + DnsMock::withMockedHosts(array( + 'baz.com' => array(array('type' => 'MX')), + '@bar"@baz.com' => array(array('type' => false)), + )); + + $this->validator->validate( + '"foo@bar"@baz.com', + new Email(array('checkMX' => true)) + ); + + $this->assertNoViolation(); + } }