diff --git a/src/Symfony/Component/Validator/Constraints/EmailValidator.php b/src/Symfony/Component/Validator/Constraints/EmailValidator.php index c8c3c5fc720b8..ec94664efd489 100644 --- a/src/Symfony/Component/Validator/Constraints/EmailValidator.php +++ b/src/Symfony/Component/Validator/Constraints/EmailValidator.php @@ -37,7 +37,7 @@ public function validate($value, Constraint $constraint) $valid = filter_var($value, FILTER_VALIDATE_EMAIL); if ($valid) { - $host = substr($value, strpos($value, '@') + 1); + $host = substr($value, strrpos($value, '@') + 1); // Check for host DNS resource records if ($valid && $constraint->checkMX) { diff --git a/src/Symfony/Component/Validator/Tests/Constraints/EmailValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/EmailValidatorTest.php index 10d17b5c68cd4..b2d74bac6516e 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/EmailValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/EmailValidatorTest.php @@ -125,4 +125,16 @@ public function getDnsChecks() array('AAAA', true), ); } + + public function testHostnameIsProperlyParsed() + { + DnsMock::withMockedHosts(array('baz.com' => array(array('type' => 'MX')))); + + $this->validator->validate( + '"foo@bar"@baz.com', + new Email(array('checkMX' => true)) + ); + + $this->assertNoViolation(); + } }