Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit eabe394

Browse files
committed
[Validator] - Bugfix for 18146 - EmailValidator cannot extract hostname if email contains multiple @ symbols
1 parent fcac5dd commit eabe394

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/Symfony/Component/Validator/Constraints/EmailValidator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function validate($value, Constraint $constraint)
3737
$valid = filter_var($value, FILTER_VALIDATE_EMAIL);
3838

3939
if ($valid) {
40-
$host = substr($value, strpos($value, '@') + 1);
40+
$host = substr(strrchr($value, '@'), 1);
4141

4242
// Check for host DNS resource records
4343
if ($valid && $constraint->checkMX) {

src/Symfony/Component/Validator/Tests/Constraints/EmailValidatorTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,19 @@ public function getInvalidEmails()
8686
array('example@localhost'),
8787
);
8888
}
89+
90+
public function testHostnameIsProperlyParsed()
91+
{
92+
DnsMock::withMockedHosts(array(
93+
'baz.com' => array(array('type' => 'MX')),
94+
'@bar"@baz.com' => array(array('type' => false)),
95+
));
96+
97+
$this->validator->validate(
98+
'"foo@bar"@baz.com',
99+
new Email(array('checkMX' => true))
100+
);
101+
102+
$this->assertNoViolation();
103+
}
89104
}

0 commit comments

Comments
 (0)