Fix for bad regexp used in PHP <= 5.3.2. Closes #897
This commit is contained in:
parent
dbdb3da6bf
commit
d235570653
@ -17,7 +17,6 @@ use Symfony\Component\Validator\Exception\UnexpectedTypeException;
|
|||||||
|
|
||||||
class EmailValidator extends ConstraintValidator
|
class EmailValidator extends ConstraintValidator
|
||||||
{
|
{
|
||||||
|
|
||||||
public function isValid($value, Constraint $constraint)
|
public function isValid($value, Constraint $constraint)
|
||||||
{
|
{
|
||||||
if (null === $value || '' === $value) {
|
if (null === $value || '' === $value) {
|
||||||
@ -29,22 +28,27 @@ class EmailValidator extends ConstraintValidator
|
|||||||
}
|
}
|
||||||
|
|
||||||
$value = (string) $value;
|
$value = (string) $value;
|
||||||
|
$valid = filter_var($value, FILTER_VALIDATE_EMAIL);
|
||||||
|
|
||||||
if (!filter_var($value, FILTER_VALIDATE_EMAIL)) {
|
if ($valid) {
|
||||||
$this->setMessage($constraint->message, array('{{ value }}' => $value));
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($constraint->checkMX) {
|
|
||||||
$host = substr($value, strpos($value, '@') + 1);
|
$host = substr($value, strpos($value, '@') + 1);
|
||||||
|
|
||||||
if (!$this->checkMX($host)) {
|
// Likely not a FQDN, bug in PHP FILTER_VALIDATE_EMAIL prior to PHP 5.3.3
|
||||||
|
if (version_compare(PHP_VERSION, '5.3.3', '<') && strpos($host, '.') === false) {
|
||||||
|
$valid = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Do not check MX records if host is invalid
|
||||||
|
if ($valid && $constraint->checkMX) {
|
||||||
|
$valid = $this->checkMX($host));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$valid) {
|
||||||
$this->setMessage($constraint->message, array('{{ value }}' => $value));
|
$this->setMessage($constraint->message, array('{{ value }}' => $value));
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user