[Validator] EmailValidator cannot extract hostname if email contains multiple @ symbols

This commit is contained in:
natechicago 2016-03-16 21:58:22 -05:00 committed by Nicolas Grekas
parent 56624e6a9d
commit c551bd17fc
2 changed files with 13 additions and 1 deletions

View File

@ -37,7 +37,7 @@ class EmailValidator extends ConstraintValidator
$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) {

View File

@ -125,4 +125,16 @@ class EmailValidatorTest extends AbstractConstraintValidatorTest
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();
}
}