Code

Opened 2 years ago

Closed 2 years ago

Last modified 2 years ago

#17100 closed Bug (fixed)

Possible bad regex for email validator

Reported by: reames@… Owned by: nobody
Component: Core (Other) Version: master
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Around line 150 of /django/core/validators.py is a line in which I think there's a missing backslash:

r'|^"([\001-\010\013\014\016-\037!#-\[\]-\177]|\\[\001-011\013\014\016-\177])*"' # quoted-string
                                missing backslash? ----^

If you look at the debug output of that part of the regex, I think the backslash is what is meant.

>>> re.compile(r'[\001-\011]', re.DEBUG)
in
  range (1, 9)
<_sre.SRE_Pattern object at 0x137e9b0>
>>> re.compile(r'[\001-011]', re.DEBUG)
in
  range (1, 48)
  literal 49
  literal 49
<_sre.SRE_Pattern object at 0x137ea48>

Given this, the following email should fail: "\12"@example.com

A test case:
assert(email_re.match('"\\\12"@example.com') == None)

Attachments (1)

17100.diff (1.5 KB) - added by claudep 2 years ago.
Fix missing backslash and tests

Download all attachments as: .zip

Change History (7)

comment:1 Changed 2 years ago by claudep

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

Changed 2 years ago by claudep

Fix missing backslash and tests

comment:2 Changed 2 years ago by claudep

  • Has patch set

comment:3 Changed 2 years ago by claudep

I think the fix should also be backported to stable branch.

comment:4 Changed 2 years ago by claudep

  • Type changed from Uncategorized to Bug
  • Version changed from 1.3 to SVN

comment:5 Changed 2 years ago by aaugustin

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

In [17349]:

Fixed #17100 -- Typo in the regex for EmailValidator. Thanks reames AT asymmetricventures com for the report and Claude Paroz for the patch.

comment:6 Changed 2 years ago by aaugustin

In [17350]:

(The changeset message doesn't reference this ticket)

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.