Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[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

Closed
wants to merge 1 commit into from

Conversation

PurpleBooth
Copy link
Contributor

@PurpleBooth PurpleBooth commented Oct 4, 2017

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.

Q A
Branch? 3.4 or master
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? no
Fixed tickets
License MIT
Doc PR

@PurpleBooth PurpleBooth force-pushed the prevent-double-dot branch 2 times, most recently from bff80cd to 65fe4bd Compare October 4, 2017 22:04
@PurpleBooth PurpleBooth changed the title Validators: Add common email typo [Validators] Add common double dot email typo Oct 4, 2017
@PurpleBooth PurpleBooth changed the title [Validators] Add common double dot email typo [Validator] Add common double dot email typo Oct 4, 2017
@PurpleBooth
Copy link
Contributor Author

I'm unsure why the the Appveyor tests are failing. It doesn't seem to be related to the code changes.

@PurpleBooth
Copy link
Contributor Author

I've just changed this to support the cases.

  • example@example..com
  • example@example.co..uk
  • example@example..co.uk
  • example@example..co..uk

@@ -78,7 +78,7 @@ public function validate($value, Constraint $constraint)

return;
}
} elseif (!preg_match('/^.+\@\S+\.\S+$/', $value)) {
} elseif (!preg_match('/^.+\@[^\s.]+(\.[^\s.]+)+$/', $value)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(?:...) (non-capturing)

Copy link
Contributor Author

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

@linaori
Copy link
Contributor

linaori commented Oct 5, 2017

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'),

@nicolas-grekas
Copy link
Member

nicolas-grekas commented Oct 5, 2017

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:

/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/

(we should just change the last * by a + to enforce a least one dot in the domain part.)

We need to find a way to make this move and get rid of the current very loose validation in 4.0.
What about throwing, in 3.4, a deprecation notice when an email doesn't pass the HTML5 validation?
That HTML5 regexp wouldn't be enforced and we would still use the current one, but then, in 4.0, we could enforce it and devs would have a way to get some notices about the issue.
Yes that wouldn't fix broken emails, but they are broken anyway, so I think we can do it in a new major version.

WDYT @symfony/deciders?

@PurpleBooth would you be up to work on this in the next days/weeks?

@linaori
Copy link
Contributor

linaori commented Oct 5, 2017

Sounds like a good idea, I like it!

@PurpleBooth
Copy link
Contributor Author

PurpleBooth commented Oct 5, 2017

Sure, I'm totally open to doing that.

Just to be clear:

  1. v4 - Use HTML5 Email Regex
  2. v3.4 - Raise depreciation notice when HTML5 Pattern isn't met?

@nicolas-grekas
Copy link
Member

@PurpleBooth correct

@xabbuh
Copy link
Member

xabbuh commented Oct 5, 2017

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 mode option that could be something like html5 or rfc(in fact, we could allow several RFC types to support the different validation schemes supported by EmailValidator 2)? This option could default to a special loose value in 3.4 to use the old simple regex.

@nicolas-grekas
Copy link
Member

@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.
Do you really think we should follow this path? I'm not sure. But if we want, we need to actually do it this time.
I still prefer the plan I proposed :)

@xabbuh
Copy link
Member

xabbuh commented Oct 5, 2017

@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.

@nicolas-grekas
Copy link
Member

@xabbuh would you be up to make that happen very soon (because feat freeze?)

@nicolas-grekas
Copy link
Member

Or @PurpleBooth of course?

@xabbuh
Copy link
Member

xabbuh commented Oct 5, 2017

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.

@PurpleBooth
Copy link
Contributor Author

PurpleBooth commented Oct 5, 2017

Would the mode option imply the need for EmailValidator, or would that always be required now?

@PurpleBooth
Copy link
Contributor Author

I've put together what I understand as the "mode" option. It needs work, but for discussion purposes #24442

@PurpleBooth PurpleBooth changed the base branch from master to 3.4 October 6, 2017 06:56
@PurpleBooth PurpleBooth force-pushed the prevent-double-dot branch 2 times, most recently from e9adf60 to 55da378 Compare October 6, 2017 07:09
@PurpleBooth
Copy link
Contributor Author

PurpleBooth commented Oct 6, 2017

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.
@nicolas-grekas
Copy link
Member

Closing in favor of #24442 then. Thanks for raising the point.

@nicolas-grekas nicolas-grekas added this to the 3.4 milestone Oct 8, 2017
@PurpleBooth PurpleBooth deleted the prevent-double-dot branch October 8, 2017 20:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.