Opened 5 years ago

Closed 5 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


There is an error in regexp "email_re" allocated here

According to this regexp e-mail address in form ipv4 address (SMTP 4.1.3) e.g. user_name@ 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) (1.9 KB) - added by vadimov@… 5 years ago.

Download all attachments as: .zip

Change History (3)

comment:1 Changed 5 years ago by anonymous

Changed 5 years ago by vadimov@…

Attachment: added


comment:2 Changed 5 years ago by Karen Tracey

Resolution: invalid
Status: newclosed

What authoritative specification are you basing the assertion that user_name@ should be accepted as valid? Every one I have checked indicates brackets around the address are required. For example from

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 [], 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@ The correct way to write that address is user_name@[], and that is accepted by the Django email validator.

Last edited 5 years ago by Karen Tracey (previous) (diff)
Note: See TracTickets for help on using tickets.
Back to Top