Skip to content

Commit

Permalink
Fixed #24349 -- Limited domain name labels to 63 characters in EmailV…
Browse files Browse the repository at this point in the history
…alidator
  • Loading branch information
atmb4u authored and timgraham committed Apr 17, 2015
1 parent b98dfc2 commit 2400329
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
5 changes: 2 additions & 3 deletions django/core/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,8 @@ class EmailValidator(object):
r'|^"([\001-\010\013\014\016-\037!#-\[\]-\177]|\\[\001-\011\013\014\016-\177])*"$)', # quoted-string
re.IGNORECASE)
domain_regex = re.compile(
# max length of the domain is 249: 254 (max email length) minus one
# period, two characters for the TLD, @ sign, & one character before @.
r'(?:[A-Z0-9](?:[A-Z0-9-]{0,247}[A-Z0-9])?\.)+(?:[A-Z]{2,6}|[A-Z0-9-]{2,}(?<!-))$',
# max length for domain name labels is 63 characters per RFC 1034
r'((?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+)(?:[A-Z0-9-]{2,63}(?<!-))$',
re.IGNORECASE)
literal_regex = re.compile(
# literal form, ipv4 or ipv6 address (SMTP 4.1.3)
Expand Down
3 changes: 3 additions & 0 deletions docs/releases/1.9.txt
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,9 @@ Validators
* Added :func:`django.core.validators.int_list_validator` to generate
validators of strings containing integers separated with a custom character.

* :class:`~django.core.validators.EmailValidator` now limits the length of
domain name labels to 63 characters per :rfc:`1034`.

Backwards incompatible changes in 1.9
=====================================

Expand Down
11 changes: 8 additions & 3 deletions tests/validators/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,12 @@
(validate_email, 'email@localhost', None),
(EmailValidator(whitelist=['localdomain']), 'email@localdomain', None),
(validate_email, '"test@test"@example.com', None),
(validate_email, 'example@atm.%s' % ('a' * 63), None),
(validate_email, 'example@%s.atm' % ('a' * 63), None),
(validate_email, 'example@%s.%s.atm' % ('a' * 63, 'b' * 10), None),

(validate_email, 'example@atm.%s' % ('a' * 64), ValidationError),
(validate_email, 'example@%s.atm.%s' % ('b' * 64, 'a' * 63), ValidationError),
(validate_email, None, ValidationError),
(validate_email, '', ValidationError),
(validate_email, 'abc', ValidationError),
Expand All @@ -69,9 +74,9 @@
(validate_email, '"\\\011"@here.com', None),
(validate_email, '"\\\012"@here.com', ValidationError),
(validate_email, '[email protected].', ValidationError),
# Max length of domain name in email is 249 (see validator for calculation)
(validate_email, 'a@%s.us' % ('a' * 249), None),
(validate_email, 'a@%s.us' % ('a' * 250), ValidationError),
# Max length of domain name labels is 63 characters per RFC 1034.
(validate_email, 'a@%s.us' % ('a' * 63), None),
(validate_email, 'a@%s.us' % ('a' * 64), ValidationError),

(validate_slug, 'slug-ok', None),
(validate_slug, 'longer-slug-still-ok', None),
Expand Down

0 comments on commit 2400329

Please sign in to comment.