8000 [Validator] - Bugfix for 18146 - EmailValidator cannot extract hostna… · symfony/symfony@aed6486 · GitHub
[go: up one dir, main page]

Skip to content

Commit aed6486

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

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public function validate($value, Constraint $constraint)
9393
return;
9494
}
9595

96-
$host = substr($value, strpos($value, '@') + 1);
96+
$host = substr(strrchr($value, '@'), 1);
9797

9898
// Check for host DNS resource records
9999
if ($constraint->checkMX) {

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ public function getValidEmails()
6969
array('fabien@symfony.com'),
7070
array('example@example.co.uk'),
7171
array('fabien_potencier@example.fr'),
72+
array('"very@uncommon"@example.com'),
7273
);
7374
}
7475

@@ -143,4 +144,19 @@ public function getDnsChecks()
143144
array('AAAA', Email::HOST_CHECK_FAILED_ERROR),
144145
);
145146
}
147+
148+
public function testHostnameIsProperlyParsed()
149+
{
150+
DnsMock::withMockedHosts(array(
151+
'baz.com' => array(array('type' => 'MX')),
152+
'@bar"@baz.com' => array(array('type' => false)),
153+
));
154+
155+
$this->validator->validate(
156+
'"foo@bar"@baz.com',
157+
new Email(array('checkMX' => true))
158+
);
159+
160+
$this->assertNoViolation();
161+
}
146162
}

0 commit comments

Comments
 (0)
0