-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[Validator][Email] - Strict validation and soft dependency #9140
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
885996b
b377295
c3241ec
ab3787a
fb36789
6574d5f
1052f3b
33cb5c5
facef8e
7ce2528
58e99b5
fadea1f
5791e36
a7ec6ab
89ca713
cf11a03
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ | |
use Symfony\Component\Validator\Constraint; | ||
use Symfony\Component\Validator\ConstraintValidator; | ||
use Symfony\Component\Validator\Exception\UnexpectedTypeException; | ||
use Egulias\EmailValidator\EmailValidator as StrictEmailValidator; | ||
|
||
/** | ||
* @author Bernhard Schussek <bschussek@gmail.com> | ||
|
@@ -22,6 +23,18 @@ | |
*/ | ||
class EmailValidator extends ConstraintValidator | ||
{ | ||
/** | ||
* isStrict | ||
* | ||
* @var Boolean | ||
*/ | ||
private $isStrict; | ||
|
||
public function __construct($strict = false) | ||
{ | ||
$this->isStrict = $strict; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
|
@@ -36,12 +49,23 @@ public function validate($value, Constraint $constraint) | |
} | ||
|
||
$value = (string) $value; | ||
$valid = filter_var($value, FILTER_VALIDATE_EMAIL); | ||
if (null === $constraint->strict) { | ||
$constraint->strict = $this->isStrict; | ||
} | ||
|
||
if ($constraint->strict && class_exists('\Egulias\EmailValidator\EmailValidator')) { | ||
$strictValidator = new StrictEmailValidator(); | ||
$valid = $strictValidator->isValid($value, false); | ||
} elseif ($constraint->strict === true) { | ||
throw new \RuntimeException('Strict email validation requires egulias/email-validator'); | ||
} else { | ||
$valid = preg_match('/.+\@.+\..+/', $value); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This fails with an IPv6 address There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are talking about the else part, which is intended to simply allow an "@" and a "." There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes it does, that's why I was saying this is still a BC break. But I did it this way because of the conversation on #1581 where, if I didn't got it wrong, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you mean BC break. BC means the opposite There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes BC break, sorry.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jakzal it's ok? Before I fix the other changes. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fine with me if it was agreed before :) |
||
} | ||
|
||
if ($valid) { | ||
$host = substr($value, strpos($value, '@') + 1); | ||
|
||
// Check for host DNS resource records | ||
|
||
if ($valid && $constraint->checkMX) { | ||
$valid = $this->checkMX($host); | ||
} elseif ($valid && $constraint->checkHost) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i also don't see an entry on the changelog
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See L9
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changelog not upgrade i mean
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no changelog file in master yet, how should I proceed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we are talking about the changelog of the component: https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Validator/CHANGELOG.md