Local email validation with apostrophe
Closed, WontfixPublic

Description

When trying to add an email address with an apostrophe / single quote (') in the local part (before the @), it fails validation.

I know I can just edit src/applications/people/storage/PhabricatorUserEmail.php, as mentioned in T12359, but I was hoping that since you added "!" to the list of acceptable characters in D8320, that you could also include an apostrophe.
This should do the trick:

$email_regex = "(^[a-z0-9_+.!'-]+@[a-z0-9_+:.-]+$)i";

https://en.wikipedia.org/wiki/Email_address#Local-part indicates that an apostrophe is an acceptable character (3rd bullet point).
To include all of them, and also to escape the "-", in case someone ever moves its position and doesn't notice that they've potentially introduced a bug:

$email_regex = "(^[a-z0-9.!#$%&'*+/=?\^_`{|}~\-]+@[a-z0-9_+:.\-]+$)i";

This passes all current tests (i.e. all addresses meant to pass, do, and likewise for all that are meant to fail).


To reproduce:

  • Set up a new account, or add an email to an existing profile.
  • Enter an otherwise valid email address, but insert an apostrophe before the @.

Expected result:

  • Email is considered valid; account is created or email is added to existing profile.

Observed result:

  • An error indicating the email address provided is invalid (though no mention of the reason).
ernie created this task.May 17 2017, 3:28 AM
ernie updated the task description. (Show Details)May 17 2017, 3:45 AM
epriestley changed the task status from Duplicate to Wontfix.
epriestley added a subscriber: epriestley.

Per T12359, we aren't interested in supporting technically-deliverable-but-bizzarely-exotic addresses in the upstream. Feel free to fork to support this kind of address.

ernie added a comment.EditedMay 17 2017, 4:22 AM

Okay, but just to point out: having an apostrophe in one's name is not that exotic...

  • O'Brien
  • O'Connor
  • D'Angelo
  • O'Dowd
  • O'Malley
  • O'Hara
  • D'Arcy
  • D'Addario

So someone could quite conceivably have Chris.O'Dowd@BBC.co.uk or something like that.
Anyway, if anyone's looking for how to get around this in the future, an alternate solution to changing PhabricatorUserEmail.php would be to go into the DB phabricator_user, in table user_email, and change it directly in there, thus bypassing validation.
If you did want to change the code, though, look into http://php.net/manual/en/filter.examples.validation.php - FILTER_VALIDATE_EMAIL and FILTER_SANITIZE_EMAIL.

ernie updated the task description. (Show Details)May 17 2017, 2:25 PM
ofbeaton added a subscriber: ofbeaton.