-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Validator] Add common double dot email typo #24429
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
Conversation
bff80cd
to
65fe4bd
Compare
65fe4bd
to
ab63bb0
Compare
I'm unsure why the the Appveyor tests are failing. It doesn't seem to be related to the code changes. |
ab63bb0
to
ca273b3
Compare
ca273b3
to
5a52e81
Compare
I've just changed this to support the cases.
|
@@ -78,7 +78,7 @@ public function validate($value, Constraint $constraint) | ||
|
||
return; | ||
} | ||
} elseif (!preg_match('/^.+\@\S+\.\S+$/', $value)) { | ||
} elseif (!preg_match('/^.+\@[^\s.]+(\.[^\s.]+)+$/', $value)) { |
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.
(?:...)
(non-capturing)
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.
Ooh! Good catch. I've added that in
5a52e81
to
5c88073
Compare
I've pulled up a list of email addresses that my company has added to a custom email checker, which are not all caught by the non-strict Symfony checker. Not saying they must be added, but it would be nice to have even more checks, making the checker more complete. array('a@a'),
array('a@a.'),
array('a@.nl'),
array('@a.nl'),
array('.email@with.a.domain'),
array('email.@with.a.domain'),
array('.email.@with.a.domain'),
array('em..ail@with.a.domain'),
array('a@a.nl;a@a.nl'),
array('a@'),
array('a@.'),
array(' a@a.nl'),
array('a@ '),
array(' a@a.nl '),
array(' a @a .nl '),
array('a@-invalid.hostname'),
array('email@with.averylongextensionbehindthedomain'),
array('email-with-dashes@a.a'), |
I don't know if we can agree on adding this rule as bug fix: on one side, I really think rejecting such emails should have been the case. On the other side, this is a BC break that may make apps display new errors to end users, or break some cron job, isn't? I would strongly suggest to move to HTML5 validation by default in Symfony 4.0:
(we should just change the last We need to find a way to make this move and get rid of the current very loose validation in 4.0. WDYT @symfony/deciders? @PurpleBooth would you be up to work on this in the next days/weeks? |
Sounds like a good idea, I like it! |
Sure, I'm totally open to doing that. Just to be clear:
|
@PurpleBooth correct |
Triggering a deprecation based on the input does not sound like a good idea to me. That's too fragile and likely to not be detected during development. What about instead introducing a |
@xabbuh that's where we stopped at in previous discussions, by consideration for broken emails. That's why I'm proposing this simple plan. Yes, it's a pushy change. But I think it will just work and we could move forward faster and make apps better by default, instead of having to play with the deprecation policy to 1. add an option, 2. for setting it, 3. deprecate it, 4. remove it, etc. |
@nicolas-grekas Well, deprecation based on user input is what looks flaky to me. I am afraid that this calls for bug reports in the future. And IIRC we already had some feature requests in the past to support more validation rules besides NoRFCWarningsValidation. So that would be the opportunity to make that happen as well. |
@xabbuh would you be up to make that happen very soon (because feat freeze?) |
Or @PurpleBooth of course? |
I can try to come up with something tonight. But I can't promise anything. So if someone can create a PR before, that would be nice. |
Would the mode option imply the need for |
I've put together what I understand as the "mode" option. It needs work, but for discussion purposes #24442 |
e9adf60
to
55da378
Compare
I've changed this to deprecate the loose pattern and raise a E_DEPRECATED as discussed. I don't really think this is a good solution as it doesn't offer people a intermediary fix path as has already been mentioned. I much prefer the mode solution in #24442 |
The most common email typo that we see in our logs is the "double dot". This is where a user types "username@example..com", rather than "username@example.com". This particular common user typo isn't a possible email address and, wasn't previously covered by the validator. Why is this added here and not strict? Strict allows some addresses like "username@example", which, while technically valid (you could use this case to address a machine with the hostname "example") are undesirable for nearly all applications. Note: This specific case is already covered under strict validations.
55da378
to
7daaa69
Compare
Closing in favor of #24442 then. Thanks for raising the point. |
The most common email typo that we see in our logs is the "double dot".
This is where a user types "username@example..com", rather than
"username@example.com". This particular common user typo isn't a
possible email address and, wasn't previously covered by the validator.
Why is this added here and not strict? Strict allows some addresses like
"username@example", which, while technically valid (you could use this
case to address a machine with the hostname "example") are undesirable
for nearly all applications.
Note: This specific case is already covered under strict validations.