Opened 13 years ago

Closed 12 years ago

Last modified 12 years ago

#17867 closed Bug (fixed)

validate_email fails with IDN domains

Reported by: Pierre <pierre.matri@…> Owned by: nobody
Component: Forms Version: 1.4-beta-1
Severity: Normal Keywords: idn
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

URLValidator has been fixed with #12988. However, validate_email still fails with IDN E-mail addresses, especially with long TLDs (see http://idn.icann.org/E-mail_test for examples).

>>> import django
>>> django.get_version()
'1.4c1'
>>>
>>> from django.core.validators import validate_email
>>> validate_email('mailtest@xn--zkc6cc5bi7f6e.xn--hlcj6aya9esc7a')
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/home/dev/coolo-django/local/lib/python2.7/site-packages/django/core/validators.py", line 155, in __call__
    super(EmailValidator, self).__call__(u'@'.join(parts))
  File "/home/dev/coolo-django/local/lib/python2.7/site-packages/django/core/validators.py", line 44, in __call__
    raise ValidationError(self.message, code=self.code)
ValidationError: [u'Enter a valid e-mail address.']
>>> validate_email('mailtest@xn--mgbh0fb.xn--kgbechtv')
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/home/dev/coolo-django/local/lib/python2.7/site-packages/django/core/validators.py", line 155, in __call__
    super(EmailValidator, self).__call__(u'@'.join(parts))
  File "/home/dev/coolo-django/local/lib/python2.7/site-packages/django/core/validators.py", line 44, in __call__
    raise ValidationError(self.message, code=self.code)
ValidationError: [u'Enter a valid e-mail address.']
>>> validate_email('mailtest@xn--hxajbheg2az3al.xn--jxalpdlp')
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/home/dev/coolo-django/local/lib/python2.7/site-packages/django/core/validators.py", line 155, in __call__
    super(EmailValidator, self).__call__(u'@'.join(parts))
  File "/home/dev/coolo-django/local/lib/python2.7/site-packages/django/core/validators.py", line 44, in __call__
    raise ValidationError(self.message, code=self.code)
ValidationError: [u'Enter a valid e-mail address.']
>>>

Attachments (2)

17867.diff (2.5 KB ) - added by Pierre <pierre.matri@…> 13 years ago.
17867.2.diff (1.7 KB ) - added by Pierre <pierre.matri@…> 13 years ago.
Working diff file. Previous one was broken.

Download all attachments as: .zip

Change History (5)

by Pierre <pierre.matri@…>, 13 years ago

Attachment: 17867.diff added

by Pierre <pierre.matri@…>, 13 years ago

Attachment: 17867.2.diff added

Working diff file. Previous one was broken.

comment:1 by Claude Paroz, 13 years ago

Triage Stage: UnreviewedAccepted

The fix is correct. Seems we forgot to fix the domain regex for email validator when we fixed it for URLs (r15502).

About tests, I don't like seeing half of email validation tests in browser:django/trunk/tests/regressiontests/forms/tests/fields.py and another half in browser:django/trunk/tests/modeltests/validators/tests.py. I'd rather have them all in modeltests. That could be taken care of by the committer.

comment:2 by Claude Paroz <claude@…>, 12 years ago

Resolution: fixed
Status: newclosed

In 273b96ef9d3acb25d69e206555412774abab6022:

Fixed #17867 -- Made email validation pass with IDN domains

Thanks Pierre Matri for the report and the initial patch.

comment:3 by Claude Paroz <claude@…>, 12 years ago

In 252cd271e88e1c60fc49c06fac9d45e4c7f8750e:

Fixed test failure after IDN domain validation fix

Refs #17867.
The address in test_email_regexp_for_performance used to take forever
(security issue), then was supposed to fail after the fix (commit 9f8287a3f).
Now we are less strict with domain validation, due to new IDN domains,
hence the validation of this address pass now.

Note: See TracTickets for help on using tickets.
Back to Top