Skip to content

Commit

Permalink
[Validator] - Bugfix for 18146 - EmailValidator cannot extract hostna…
Browse files Browse the repository at this point in the history
…me if email contains multiple @ symbols
  • Loading branch information
natechicago committed Mar 17, 2016
1 parent bcb1b2d commit aed6486
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
Expand Up @@ -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) {
Expand Down
Expand Up @@ -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'),
);
}

Expand Down Expand Up @@ -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();
}
}

0 comments on commit aed6486

Please sign in to comment.