Skip to content

Commit

Permalink
EmailValidator with IDN fails on hyphen #2
Browse files Browse the repository at this point in the history
  • Loading branch information
mapeveri committed Nov 22, 2020
1 parent 9f02bd6 commit 44ff9b5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Rule/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class Email extends Rule

protected function validateValue($value, DataSetInterface $dataSet = null): Result
{
$originalValue = $value;
$result = new Result();

if (!is_string($value)) {
Expand Down Expand Up @@ -93,6 +94,10 @@ protected function validateValue($value, DataSetInterface $dataSet = null): Resu
}
}

if ($this->enableIDN && $valid === false) {
$valid = filter_var($originalValue, FILTER_VALIDATE_EMAIL) ? true : false;
}

if ($valid === false) {
$result->addError($this->translateMessage($this->message));
}
Expand Down
1 change: 1 addition & 0 deletions tests/Rule/EmailTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public function testValidateIdn(): void
->enableIDN(true);

$this->assertTrue($validator->validate('5011@example.com')->isValid());
$this->assertTrue($validator->validate('test-@dummy.com')->isValid());
$this->assertTrue($validator->validate('example@äüößìà.de')->isValid());
$this->assertTrue($validator->validate('example@xn--zcack7ayc9a.de')->isValid());
$this->assertTrue($validator->validate('info@örtliches.de')->isValid());
Expand Down

0 comments on commit 44ff9b5

Please sign in to comment.