Opened 12 years ago

Closed 12 years ago

#18758 closed Cleanup/optimization (fixed)

non-DRY e-mail regex

Reported by: Jiri Suchan Owned by: nobody
Component: Uncategorized Version: 1.4
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

There are two similar regexes having the same purpose (email validation). Keep only one of them.

Occurences:

django/core/validators.py, line 159:

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'|\[(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)

django/contrib/auth/management/commands/createsuperuser.py, line 19:

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-Z]{2,6}$', re.IGNORECASE)  # domain

Change History (4)

comment:1 by Claude Paroz, 12 years ago

Triage Stage: UnreviewedAccepted

comment:2 by Russell Keith-Magee, 12 years ago

As a side note: I've inadvertently addressed this as part of my work for #3011. In order to support arbitrary user models, it made sense to fall back to model-level validation of the fields on the user model. This removes the need for a second email regex definition.

I'll leave the ticket open because the problem is real, but as advice to anyone looking for a ticket to work on -- it's worth looking elsewhere, because a patch for this problem specifically will probably be overlooked in the long term.

comment:3 by Jiri Suchan, 12 years ago

This ticket can be closed now (fixed in #3011).

comment:4 by Claude Paroz, 12 years ago

Resolution: fixed
Status: newclosed
Note: See TracTickets for help on using tickets.
Back to Top