Skip to content
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

EmailValidator for wtforms: replace our own regex based routine with one stolen from Notify #431

Merged
merged 2 commits into from
Jul 23, 2018

Conversation

risicle
Copy link
Contributor

@risicle risicle commented Jul 23, 2018

https://trello.com/c/7m7tPP83/379-email-validation-should-we-use-notifys
https://trello.com/c/LD2eVPTY/368-supplier-user-can-be-created-but-no-email-sent

This is a fairly straightforward port. You'll see the tests needed minimal changes, mostly moving addresses over from what was previously considered "valid" to what's now considered "invalid" and making up a few replacement valid ones that are a bit tamer.

Thinking again, I'm actually probably going to make this a major bump as technically the validator's constructor call signature has changed, not accepting a regex override as the previous implementation, inheriting from the regex validator, did.

…one stolen from Notify

This will ensure we don't get any nasty surprises when attempting to send
emails to addresses for which it's too late to display sensible validation
error for.

Largely copied from
https://github.com/alphagov/notifications-utils/blob/67889886ec1476136d12e7f32787a7dbd0574cc2/notifications_utils/recipients.py#L439
onwards
@risicle risicle requested review from lfdebrux, benvand and Wynndow July 23, 2018 12:31
@risicle risicle force-pushed the ris-email-validator-from-notify branch from 777795a to 3207b0a Compare July 23, 2018 12:43
_INVALID_LOCAL_CHARS = r"\s\",;:@£“”‘’"
_email_regex = re.compile(r'^[^{}]+@([^.@][^@]+)$'.format(_INVALID_LOCAL_CHARS))
_hostname_part = re.compile(r'^(xn-|[a-z0-9]+)(-[a-z0-9]+)*$', re.IGNORECASE)
_tld_part = re.compile(r'^([a-z]{2,63}|xn--([a-z0-9]+-)*[a-z0-9]+)$', re.IGNORECASE)
Copy link
Contributor

Choose a reason for hiding this comment

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

what's with the xns here and for the hostname?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@risicle risicle merged commit 7803b84 into master Jul 23, 2018
@risicle risicle deleted the ris-email-validator-from-notify branch July 23, 2018 13:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants