bug #18147 [Validator] EmailValidator cannot extract hostname if email contains multiple @ symbols (natechicago)

This PR was squashed before being merged into the 2.3 branch (closes #18147).

Discussion
----------

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

| Q             | A
| ------------- | ---
| Branch        | 2.3
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #18146
| License       | MIT
| Doc PR        | n/a

Commits
-------

c551bd1 [Validator] EmailValidator cannot extract hostname if email contains multiple @ symbols
This commit is contained in:
Nicolas Grekas 2016-03-17 15:26:27 +01:00
commit d2208301ee
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();
}
}