#27469: Email crashes cryptically when emptystring passed to
django.core.mail.message.sanitize_address
-------------------------------------+-------------------------------------
               Reporter:  Jarek      |          Owner:  nobody
  Glowacki                           |
                   Type:  Bug        |         Status:  new
              Component:  Core       |        Version:  master
  (Mail)                             |       Keywords:  sanitize_address
               Severity:  Normal     |  mail
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  1
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 {{{
 In [10]: sanitize_address('', 'utf-8')
 ---------------------------------------------------------------------------
 IndexError                                Traceback (most recent call
 last)
 <ipython-input-10-ad3601147d6a> in <module>()
 ----> 1 sanitize_address('', 'utf-8')

 /usr/local/lib/python3.5/site-packages/django/core/mail/message.py in
 sanitize_address(addr, encoding)
     159
     160     try:
 --> 161         address = Address(nm, addr_spec=addr)
     162     except (InvalidHeaderDefect, NonASCIILocalPartDefect):
     163         localpart, domain = split_addr(addr, encoding)

 /usr/local/lib/python3.5/email/headerregistry.py in __init__(self,
 display_name, username, domain, addr_spec)
      40                 raise TypeError("addrspec specified when username
 and/or "
      41                                 "domain also specified")
 ---> 42             a_s, rest = parser.get_addr_spec(addr_spec)
      43             if rest:
      44                 raise ValueError("Invalid addr_spec; only '{}' "

 /usr/local/lib/python3.5/email/_header_value_parser.py in
 get_addr_spec(value)
    1986     """
    1987     addr_spec = AddrSpec()
 -> 1988     token, value = get_local_part(value)
    1989     addr_spec.append(token)
    1990     if not value or value[0] != '@':

 /usr/local/lib/python3.5/email/_header_value_parser.py in
 get_local_part(value)
    1798     local_part = LocalPart()
    1799     leader = None
 -> 1800     if value[0] in CFWS_LEADER:
    1801         leader, value = get_cfws(value)
    1802     if not value:

 IndexError: string index out of range
 }}}

 Could we reraise some more intuitive error back to the user for this case?

 A single `@` symbol also raises an exception for this method, but at least
 it yields a more meaningful error that the dev can track down:
 `HeaderParseError: Expected 'atom' or 'quoted-string' but found '@'`
 Though maybe this could be beefed up to something nicer also.

--
Ticket URL: <https://code.djangoproject.com/ticket/27469>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/050.114d26e3821d6adb5f5fbcf86d1ddb37%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to