updated email_regexp and added test cases#4001
updated email_regexp and added test cases#4001ulissesalmeida merged 4 commits intoheartcombo:masterfrom kimgb:email_regexp
Conversation
|
Having sent the PR - I've solved one particular issue relating to a false negative, but I wonder that an increasingly complex validation is wise? Domains and emails are not simple validations, and I'd worry there are other false negatives waiting to happen. I wonder if it wouldn't be better to fall back to a simple regexp e.g. Alternatively, more email test cases of the "valid, but unusual" kind. Just a thought. |
|
As @ulissesalmeida pointed out, the general thought behind the default email validation is to be as permissive as possible, while catching some obvious cases of invalid email addresses. To keep it really minimal, I would suggest applying only 4 simple rules:
The regex below implements these rules: /(?!.*\.\.)(?=\A[^@\s]+@[^@\s]+\z).*[[:alnum:]]\z/That is the most permissive validation I can think of. Its rules are almost compatible with the current regex, except for a few special cases. Scenarios where it gets more restrictive:
Scenarios where it gets more permissive:
|
|
If we want to keep backwards compatibility, we should not add new restrictions. Adding no new restrictions ensures we won't break existing apps on upgrade. In order to do that, we need to drop rules /\A[^@\s]+@[^@\s]+\z/It drops 2 restrictions from the current ruleset:
|
|
I've since done more reading on email localparts and it doesn't get any easier. While highly unusual, localparts do permit a quoted string that can include a range of characters normally disallowed - including spaces, consecutive dots and Supporting this would mean dropping/rewriting the 2 remaining restrictions as listed by @britto above, to something like |
|
If backwards compatibility is important why we don't change only the configured email regexp in the generated configuration? https://github.com/plataformatec/devise/blob/b397d33246ae3dbc725f681a3f718a20d34313af/lib/generators/templates/devise.rb#L156 That way new applications will have a better default, existing applications don't need to worry about breaking compatibility by mistake only because the library was upgraded and how want to break compatibility can just use the install generator to use the new regexp. |
|
@kimgb @rafaelfranca Good points. Actually, I feel the default regexp should be the same as the generator regexp. Like any other default, for that matter. Currently only a few generated configs differ from their default values, such as |
|
@kimgb I think we can follow @rafaelfranca idea. We should release first a deprecation warning about and make the configuration explicit.
I think we can use @britto regex. We should no worry about quoted e-mails now. What do you think? |
|
Issue related: #3997 |
|
OK - I've reverted to the older, more permissive regex |
|
@kimgb After the release of Best |
|
@kimgb I think something happened after your rebase, the PR still have conflicts and there's commits that is already on master. |
|
Yes, definitely no idea how to use rebase! Tidied up some, but still conflicts. I think maybe I misunderstood the part about removing deprecation warnings? |
|
I was using rebase fine, just needed to get past my aversion to rewriting history. I removed deprecation warnings, but only about |
|
@kimgb Yep, totally right. Now it looks very good. Thanks! \o/ |
updated
Devise::email_regexpto meet existing test cases plus valid emails"test@tt"&"test@valid---domain.com", non valid emails"test_user@example..server"&"test_user@example-.server".