Skip to content

Commit

Permalink
Remove HTML5_EMAIL_REGEX workaround
Browse files Browse the repository at this point in the history
This is no longer necessary since Colander 1.7.0 changed its default
email regex to match the one from the WhatWG HTML spec.

See:

* 759e0b9
* Pylons/colander#324
* Pylons/colander#283
  • Loading branch information
seanh committed May 17, 2019
1 parent 84c8b0c commit 4644768
Showing 1 changed file with 5 additions and 23 deletions.
28 changes: 5 additions & 23 deletions h/schemas/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,11 @@
import colander


# Regex for email addresses.
#
# Taken from Chromium and derived from the WhatWG HTML spec
# (4.10.7.1.5 E-Mail state).
#
# This was chosen because it is a widely used and relatively simple pattern.
# Unlike `colander.Email` it supports International Domain Names (IDNs) in
# Punycode form.
HTML5_EMAIL_REGEX = (
"^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@" "[a-zA-Z0-9-]+(?:\\.[a-zA-Z0-9-]+)*$"
)


class Email(colander.Regex):
"""
Validator for email addresses.
This is a replacement for `colander.Email` which rejects certain valid email
addresses (see https://github.com/hypothesis/h/issues/4662).
"""

def __init__(self, msg="Invalid email address."):
super(Email, self).__init__(HTML5_EMAIL_REGEX, msg=msg)
class Email(colander.Email):
def __init__(self, *args, **kwargs):
if "msg" not in kwargs:
kwargs["msg"] = "Invalid email address."
super(Email, self).__init__(*args, **kwargs)


class Length(colander.Length):
Expand Down

0 comments on commit 4644768

Please sign in to comment.