8000 [Validator] EmailValidator cannot extract hostname if email contains multiple @ symbols by natechicago · Pull Request #18147 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
[Validator] - Bugfix for 18146 - EmailValidator cannot extract hostna…
…me if email contains multiple @ symbols
  • Loading branch information
natechicago committed Mar 17, 2016
commit e64c3bc176d928fb4c39bc9c13d6b0283325388d
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function validate($value, Constraint $constraint)
$valid = filter_var($value, FILTER_VALIDATE_EMAIL);

if ($valid) {
$host = substr($value, strpos($value, '@') + 1);
$host = substr(strrchr($value, '@'), 1);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

substr($value, strrpos($value, '@') + 1); would be faster (less string copies)


// Check for host DNS resource records
if ($valid && $constraint->checkMX) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,19 @@ public function getDnsChecks()
array('AAAA', true),
);
}

public function testHostnameIsProperlyParsed()
{
DnsMock::withMockedHosts(array(
'baz.com' => array(array('type' => 'MX')),
'@bar"@baz.com' => array(array('type' => false)),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you don't need this line: the list of moked hosts is exclusive and a look up for this last host would fail anyway

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

K, changes have been pushed.

));

$this->validator->validate(
'"foo@bar"@baz.com',
new Email(array('checkMX' => true))
);

$this->assertNoViolation();
}
}
0