Skip to content

Commit

Permalink
Use a library for email validation (#26503)
Browse files Browse the repository at this point in the history
  • Loading branch information
phroggyy authored and taylorotwell committed Nov 14, 2018
1 parent 97b3f1b commit c071123
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"ext-openssl": "*",
"doctrine/inflector": "^1.1",
"dragonmantank/cron-expression": "^2.0",
"egulias/email-validator": "~2.0",
"erusev/parsedown": "^1.7",
"league/flysystem": "^1.0.8",
"monolog/monolog": "^1.12",
Expand Down
4 changes: 3 additions & 1 deletion src/Illuminate/Validation/Concerns/ValidatesAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
use Illuminate\Validation\Rules\Exists;
use Illuminate\Validation\Rules\Unique;
use Illuminate\Validation\ValidationData;
use Egulias\EmailValidator\EmailValidator;
use Symfony\Component\HttpFoundation\File\File;
use Egulias\EmailValidator\Validation\RFCValidation;
use Symfony\Component\HttpFoundation\File\UploadedFile;

trait ValidatesAttributes
Expand Down Expand Up @@ -590,7 +592,7 @@ public function validateDistinct($attribute, $value, $parameters)
*/
public function validateEmail($attribute, $value)
{
return filter_var($value, FILTER_VALIDATE_EMAIL) !== false;
return (new EmailValidator)->isValid($value, new RFCValidation);

This comment has been minimized.

Copy link
@martinbean

martinbean Nov 16, 2018

Contributor

Rather than new-ing up an EmailValidator instance, it might be good to resolve this from the container? That way developers can use a different email validator instance if they want to use a different validation implementation that the library offers (https://github.com/egulias/EmailValidator/tree/8036f2bd0539b6706b90217ae921782c936c5995/EmailValidator/Validation).

}

/**
Expand Down
1 change: 1 addition & 0 deletions src/Illuminate/Validation/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"require": {
"php": "^7.1.3",
"ext-json": "*",
"egulias/email-validator": "~2.0",
"illuminate/container": "5.8.*",
"illuminate/contracts": "5.8.*",
"illuminate/support": "5.8.*",
Expand Down
10 changes: 8 additions & 2 deletions tests/Validation/ValidationValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -386,10 +386,10 @@ public function testInputIsReplaced()
{
$trans = $this->getIlluminateArrayTranslator();
$trans->addLines(['validation.email' => ':input is not a valid email'], 'en');
$v = new Validator($trans, ['email' => 'a@s'], ['email' => 'email']);
$v = new Validator($trans, ['email' => 'a@@s'], ['email' => 'email']);
$this->assertFalse($v->passes());
$v->messages()->setFormat(':message');
$this->assertEquals('a@s is not a valid email', $v->messages()->first('email'));
$this->assertEquals('a@@s is not a valid email', $v->messages()->first('email'));

$trans = $this->getIlluminateArrayTranslator();
$trans->addLines(['validation.email' => ':input is not a valid email'], 'en');
Expand Down Expand Up @@ -1969,6 +1969,12 @@ public function testValidateEmail()
$this->assertTrue($v->passes());
}

public function testValidateEmailWithInternationalCharacters()
{
$v = new Validator($this->getIlluminateArrayTranslator(), ['x' => 'foo@gmäil.com'], ['x' => 'email']);
$this->assertTrue($v->passes());
}

/**
* @dataProvider validUrls
*/
Expand Down

0 comments on commit c071123

Please sign in to comment.