Ticket #12005: email.patch

File email.patch, 1.9 KB (added by Gumnos, 15 years ago)

Updated patch against trunk with test included

  • django/forms/fields.py

     
    418418            raise ValidationError(self.error_messages['invalid'])
    419419        return value
    420420
    421 email_re = re.compile(
    422     r"(^[-!#$%&'*+/=?^_`{}|~0-9A-Z]+(\.[-!#$%&'*+/=?^_`{}|~0-9A-Z]+)*"  # dot-atom
    423     r'|^"([\001-\010\013\014\016-\037!#-\[\]-\177]|\\[\001-011\013\014\016-\177])*"' # quoted-string
    424     r')@(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+[A-Z]{2,6}\.?$', re.IGNORECASE)  # domain
     421email_re = re.compile(r"""^                     # start-of-line
     422    (
     423        [-!#$%&'*+/=?^_`{}|~0-9A-Z]+
     424        (\.[-!#$%&'*+/=?^_`{}|~0-9A-Z]+)*       # dot-atom
     425    |
     426        "([\001-\010\013\014\016-\037!#-\[\]-\177]
     427        |\\[\001-011\013\014\016-\177])*"       # quoted-string
     428    )                                           # user
     429    @
     430    ((?:[A-Z0-9]|[A-Z0-9]-+(?=[A-Z0-9]))+\.)*   # subdomains
     431    (?:[A-Z0-9](?:[A-Z0-9]|-+(?=[A-Z0-9]))+\.)+ # domain
     432    [A-Z]{2,6}                                  # TLD
     433    $                                           # end of line
     434    """, re.IGNORECASE | re.VERBOSE)  # domain
    425435
    426436class EmailField(RegexField):
    427437    default_error_messages = {
  • tests/regressiontests/forms/fields.py

     
    767767>>> f.clean('example@valid-with-hyphens.com')
    768768u'example@valid-with-hyphens.com'
    769769
     770>>> f.clean('example@a.single.letter.subdomain.com')
     771u'example@a.single.letter.subdomain.com'
     772
    770773# Check for runaway regex security problem. This will take for-freeking-ever
    771774# if the security fix isn't in place.
    772775>>> f.clean('viewx3dtextx26qx3d@yahoo.comx26latlngx3d15854521645943074058')
Back to Top