Skip to content
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

[5.8] Email validation will reject non-string values #27735

Merged
merged 5 commits into from
Mar 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 4 additions & 0 deletions src/Illuminate/Validation/Concerns/ValidatesAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,10 @@ protected function extractDistinctValues($attribute)
*/
public function validateEmail($attribute, $value)
{
if (! is_string($value) && ! (is_object($value) && method_exists($value, '__toString'))) {
return false;
}

return (new EmailValidator)->isValid($value, new RFCValidation);
}

Expand Down
19 changes: 19 additions & 0 deletions tests/Validation/ValidationValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2016,6 +2016,25 @@ public function testValidateEmail()
$v = new Validator($trans, ['x' => 'aslsdlks'], ['x' => 'Email']);
$this->assertFalse($v->passes());

$v = new Validator($trans, ['x' => ['not a string']], ['x' => 'Email']);
$this->assertFalse($v->passes());

$v = new Validator($trans, ['x' => new class {
public function __toString()
{
return 'aslsdlks';
}
}], ['x' => 'Email']);
$this->assertFalse($v->passes());

$v = new Validator($trans, ['x' => new class {
public function __toString()
{
return 'foo@gmail.com';
}
}], ['x' => 'Email']);
$this->assertTrue($v->passes());

$v = new Validator($trans, ['x' => 'foo@gmail.com'], ['x' => 'Email']);
$this->assertTrue($v->passes());
}
Expand Down