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

Skip to content

Commit e64c3bc

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

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
@@ -125,4 +125,19 @@ public function getDnsChecks()
125125
array('AAAA', true),
126126
);
127127
}
128+
129+
public function testHostnameIsProperlyParsed()
130+
{
131+
DnsMock::withMockedHosts(array(
132+
'baz.com' => array(array('type' => 'MX')),
133+
'@bar"@baz.com' => array(array('type' => false)),
134+
));
135+
136+
$this->validator->validate(
137+
'"foo@bar"@baz.com',
138+
new Email(array('checkMX' => true))
139+
);
140+
141+
$this->assertNoViolation();
142+
}
128143
}

0 commit comments

Comments
 (0)