Skip to content

Commit

Permalink
Use a library for email validation
Browse files Browse the repository at this point in the history
  • Loading branch information
phroggyy committed Nov 13, 2018
1 parent f737c23 commit ea1f631
Show file tree
Hide file tree
Showing 3 changed files with 12 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);
}

/**
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 ea1f631

Please sign in to comment.