Skip to content

Commit 2400329

Browse files
atmb4utimgraham
authored andcommitted
Fixed #24349 -- Limited domain name labels to 63 characters in EmailValidator
1 parent b98dfc2 commit 2400329

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

django/core/validators.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,8 @@ class EmailValidator(object):
142142
r'|^"([\001-\010\013\014\016-\037!#-\[\]-\177]|\\[\001-\011\013\014\016-\177])*"$)', # quoted-string
143143
re.IGNORECASE)
144144
domain_regex = re.compile(
145-
# max length of the domain is 249: 254 (max email length) minus one
146-
# period, two characters for the TLD, @ sign, & one character before @.
147-
r'(?:[A-Z0-9](?:[A-Z0-9-]{0,247}[A-Z0-9])?\.)+(?:[A-Z]{2,6}|[A-Z0-9-]{2,}(?<!-))$',
145+
# max length for domain name labels is 63 characters per RFC 1034
146+
r'((?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+)(?:[A-Z0-9-]{2,63}(?<!-))$',
148147
re.IGNORECASE)
149148
literal_regex = re.compile(
150149
# literal form, ipv4 or ipv6 address (SMTP 4.1.3)

docs/releases/1.9.txt

+3
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,9 @@ Validators
242242
* Added :func:`django.core.validators.int_list_validator` to generate
243243
validators of strings containing integers separated with a custom character.
244244

245+
* :class:`~django.core.validators.EmailValidator` now limits the length of
246+
domain name labels to 63 characters per :rfc:`1034`.
247+
245248
Backwards incompatible changes in 1.9
246249
=====================================
247250

tests/validators/tests.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,12 @@
4545
(validate_email, 'email@localhost', None),
4646
(EmailValidator(whitelist=['localdomain']), 'email@localdomain', None),
4747
(validate_email, '"test@test"@example.com', None),
48+
(validate_email, 'example@atm.%s' % ('a' * 63), None),
49+
(validate_email, 'example@%s.atm' % ('a' * 63), None),
50+
(validate_email, 'example@%s.%s.atm' % ('a' * 63, 'b' * 10), None),
4851

52+
(validate_email, 'example@atm.%s' % ('a' * 64), ValidationError),
53+
(validate_email, 'example@%s.atm.%s' % ('b' * 64, 'a' * 63), ValidationError),
4954
(validate_email, None, ValidationError),
5055
(validate_email, '', ValidationError),
5156
(validate_email, 'abc', ValidationError),
@@ -69,9 +74,9 @@
6974
(validate_email, '"\\\011"@here.com', None),
7075
(validate_email, '"\\\012"@here.com', ValidationError),
7176
(validate_email, '[email protected].', ValidationError),
72-
# Max length of domain name in email is 249 (see validator for calculation)
73-
(validate_email, 'a@%s.us' % ('a' * 249), None),
74-
(validate_email, 'a@%s.us' % ('a' * 250), ValidationError),
77+
# Max length of domain name labels is 63 characters per RFC 1034.
78+
(validate_email, 'a@%s.us' % ('a' * 63), None),
79+
(validate_email, 'a@%s.us' % ('a' * 64), ValidationError),
7580

7681
(validate_slug, 'slug-ok', None),
7782
(validate_slug, 'longer-slug-still-ok', None),

0 commit comments

Comments
 (0)