bug #14853 [Validator] more strict e-mail validation regex (xabbuh)

This PR was merged into the 2.6 branch.

Discussion
----------

[Validator] more strict e-mail validation regex

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #14848
| License       | MIT
| Doc PR        |

Commits
-------

6491033 [Validator] more strict e-mail validation regex
This commit is contained in:
Fabien Potencier 2015-06-23 19:31:35 +02:00
commit dac15524ea
2 changed files with 2 additions and 3 deletions

View File

@ -24,8 +24,6 @@ use Symfony\Component\Validator\Exception\UnexpectedTypeException;
class EmailValidator extends ConstraintValidator
{
/**
* isStrict
*
* @var bool
*/
private $isStrict;
@ -73,7 +71,7 @@ class EmailValidator extends ConstraintValidator
return;
}
} elseif (!preg_match('/.+\@.+\..+/', $value)) {
} elseif (!preg_match('/^.+\@\S+\.\S+$/', $value)) {
$this->buildViolation($constraint->message)
->setParameter('{{ value }}', $this->formatValue($value))
->setCode(Email::INVALID_FORMAT_ERROR)

View File

@ -91,6 +91,7 @@ class EmailValidatorTest extends AbstractConstraintValidatorTest
array('example'),
array('example@'),
array('example@localhost'),
array('foo@example.com bar'),
);
}