Opened 13 years ago

Closed 13 years ago

#17483 closed Bug (invalid)

EmailField : valid email address

Reported by: vadimov@… Owned by: nobody
Component: Core (Mail) Version: 1.3
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

There is an error in regexp "email_re" allocated here
https://code.djangoproject.com/browser/django/trunk/django/core/validators.py#L161

According to this regexp e-mail address in form ipv4 address (SMTP 4.1.3) e.g. user_name@123.123.123.12 is not matched.

Correct regexp :

email_re = re.compile(
    r"(^[-!#$%&'*+/=?^_`{}|~0-9A-Z]+(\.[-!#$%&'*+/=?^_`{}|~0-9A-Z]+)*"  # dot-atom
    r'|^"([\001-\010\013\014\016-\037!#-\[\]-\177]|\\[\001-011\013\014\016-\177])*"' # quoted-string
    r')@(((?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+[A-Z]{2,6}\.?$)'  # 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)

Attachments (1)

email.py (1.9 KB ) - added by vadimov@… 13 years ago.
Example

Download all attachments as: .zip

Change History (3)

comment:1 by anonymous, 13 years ago

by vadimov@…, 13 years ago

Attachment: email.py added

Example

comment:2 by Karen Tracey, 13 years ago

Resolution: invalid
Status: newclosed

What authoritative specification are you basing the assertion that user_name@123.123.123.12 should be accepted as valid? Every one I have checked brackets around the address are required. For example from http://www.ietf.org/rfc/rfc2821.txt:

4.1.3 Address Literals

   Sometimes a host is not known to the domain name system and
   communication (and, in particular, communication to report and repair
   the error) is blocked.  To bypass this barrier a special literal form
   of the address is allowed as an alternative to a domain name.  For
   IPv4 addresses, this form uses four small decimal integers separated
   by dots and enclosed by brackets such as [123.255.37.2], which
   indicates an (IPv4) Internet Address in sequence-of-octets form. 

My reading of the spec is that the brackets are required, thus removing them from the regex would be wrong. The validator is correctly failing to validate user_name@123.123.123.12. The correct way to write that address is user_name@[123.123.123.12], and that is accepted by the Django email validator.

Version 0, edited 13 years ago by Karen Tracey (next)
Note: See TracTickets for help on using tickets.
Back to Top