Opened 3 years ago

Closed 3 years ago

#18758 closed Cleanup/optimization (fixed)

non-DRY e-mail regex

Reported by: yedpodtrzitko 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


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


django/core/, line 159:

email_re = re.compile(
    r"(^[-!#$%&'*+/=?^_`{}|~0-9A-Z]+(\.[-!#$%&'*+/=?^_`{}|~0-9A-Z]+)*"  # dot-atom
    # quoted-string, see also
    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/, 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 Changed 3 years ago by claudep

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

comment:2 Changed 3 years ago by russellm

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 Changed 3 years ago by yedpodtrzitko

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

comment:4 Changed 3 years ago by claudep

  • Resolution set to fixed
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.
Back to Top