Code

Opened 2 years ago

Closed 2 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@… 2 years ago.
Example

Download all attachments as: .zip

Change History (3)

comment:1 Changed 2 years ago by anonymous

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

Changed 2 years ago by vadimov@…

Example

comment:2 Changed 2 years ago by kmtracey

  • Resolution set to invalid
  • Status changed from new to closed

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 indicates 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.

Last edited 2 years ago by kmtracey (previous) (diff)

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.