summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaude Paroz <claude@2xlibre.net>2012-10-09 15:01:38 +0200
committerClaude Paroz <claude@2xlibre.net>2012-10-09 15:08:32 +0200
commit273b96ef9d3acb25d69e206555412774abab6022 (patch)
tree4d4c1f9d2df0b2b7a52a6c72efc9f15d51f4cb77
parent8cb9968a91cf533cb82e1e13948551e91b510878 (diff)
Fixed #17867 -- Made email validation pass with IDN domains
Thanks Pierre Matri for the report and the initial patch.
-rw-r--r--django/core/validators.py2
-rw-r--r--tests/modeltests/validators/tests.py1
2 files changed, 2 insertions, 1 deletions
diff --git a/django/core/validators.py b/django/core/validators.py
index c7bda682ac..251b5d8856 100644
--- a/django/core/validators.py
+++ b/django/core/validators.py
@@ -99,7 +99,7 @@ email_re = re.compile(
r"(^[-!#$%&'*+/=?^_`{}|~0-9A-Z]+(\.[-!#$%&'*+/=?^_`{}|~0-9A-Z]+)*" # dot-atom
# quoted-string, see also http://tools.ietf.org/html/rfc2822#section-3.2.5
r'|^"([\001-\010\013\014\016-\037!#-\[\]-\177]|\\[\001-\011\013\014\016-\177])*"'
- r')@((?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+[A-Z]{2,6}\.?$)' # domain
+ r')@((?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+(?:[A-Z]{2,6}\.?|[A-Z0-9-]{2,}\.?)$)' # 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, _('Enter a valid email address.'), 'invalid')
diff --git a/tests/modeltests/validators/tests.py b/tests/modeltests/validators/tests.py
index 5f93b1631b..0174a606df 100644
--- a/tests/modeltests/validators/tests.py
+++ b/tests/modeltests/validators/tests.py
@@ -28,6 +28,7 @@ TEST_DATA = (
(validate_email, 'email@[127.0.0.1]', None),
(validate_email, 'example@valid-----hyphens.com', None),
(validate_email, 'example@valid-with-hyphens.com', None),
+ (validate_email, 'test@domain.with.idn.tld.उदाहरण.परीक्षा', None),
(validate_email, None, ValidationError),
(validate_email, '', ValidationError),