summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnoop Thomas Mathew <atmb4u@gmail.com>2015-04-15 00:12:49 +0530
committerTim Graham <timograham@gmail.com>2015-04-17 18:08:33 -0400
commit24003295088ec24d823f66bd5c8b917478b24c5d (patch)
treea6c1d396b42ad2b55c1142f7a915ec82226bbf31
parentb98dfc21770bb0ddc57ca34ddecf1576c2d9f176 (diff)
Fixed #24349 -- Limited domain name labels to 63 characters in EmailValidator
-rw-r--r--django/core/validators.py5
-rw-r--r--docs/releases/1.9.txt3
-rw-r--r--tests/validators/tests.py11
3 files changed, 13 insertions, 6 deletions
diff --git a/django/core/validators.py b/django/core/validators.py
index a62f04e1a3..3e4e744ff3 100644
--- a/django/core/validators.py
+++ b/django/core/validators.py
@@ -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)
diff --git a/docs/releases/1.9.txt b/docs/releases/1.9.txt
index 25da6978ba..9fe8e9b195 100644
--- a/docs/releases/1.9.txt
+++ b/docs/releases/1.9.txt
@@ -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
=====================================
diff --git a/tests/validators/tests.py b/tests/validators/tests.py
index 4be4b9de4f..cf0ba908c2 100644
--- a/tests/validators/tests.py
+++ b/tests/validators/tests.py
@@ -45,7 +45,12 @@ TEST_DATA = [
(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),
@@ -69,9 +74,9 @@ TEST_DATA = [
(validate_email, '"\\\011"@here.com', None),
(validate_email, '"\\\012"@here.com', ValidationError),
(validate_email, 'trailingdot@shouldfail.com.', 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),