Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed #16166 - `EmailField` does not comply with SMTP standard

Thanks to qqq1one@yahoo.com for the report, and samufuentes for the patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@16355 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 66436ad171d8c442037bb03e9bc1a0f99e194ac8 1 parent 430b819
@spookylukey spookylukey authored
View
3  django/core/validators.py
@@ -135,7 +135,8 @@ def __call__(self, value):
email_re = re.compile(
r"(^[-!#$%&'*+/=?^_`{}|~0-9A-Z]+(\.[-!#$%&'*+/=?^_`{}|~0-9A-Z]+)*" # dot-atom
r'|^"([\001-\010\013\014\016-\037!#-\[\]-\177]|\\[\001-011\013\014\016-\177])*"' # quoted-string
- r')@(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+[A-Z]{2,6}\.?$', re.IGNORECASE) # domain
+ r')@((?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+[A-Z]{2,6}\.?$)' # domain
+ r'|\[(25[0-5]|2[0-4]\d|[0-1]?\d?\d)(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3}\]$', re.IGNORECASE) # literal form, ipv4 address (SMTP 4.1.3)
validate_email = EmailValidator(email_re, _(u'Enter a valid e-mail address.'), 'invalid')
slug_re = re.compile(r'^[-\w]+$')
View
2  tests/modeltests/validators/tests.py
@@ -22,12 +22,14 @@
(validate_email, 'email@here.com', None),
(validate_email, 'weirder-email@here.and.there.com', None),
+ (validate_email, 'email@[127.0.0.1]', None),
(validate_email, None, ValidationError),
(validate_email, '', ValidationError),
(validate_email, 'abc', ValidationError),
(validate_email, 'a @x.cz', ValidationError),
(validate_email, 'something@@somewhere.com', ValidationError),
+ (validate_email, 'email@127.0.0.1', ValidationError),
(validate_slug, 'slug-ok', None),
(validate_slug, 'longer-slug-still-ok', None),

0 comments on commit 66436ad

Please sign in to comment.
Something went wrong with that request. Please try again.