#35440: Update parse_header_parameters to leverage the parsing logic from 
(stdlib)
email Message.
-------------------------------------+-------------------------------------
     Reporter:  Natalia Bidart       |                    Owner:  Pravin
         Type:                       |                   Status:  assigned
  Cleanup/optimization               |
    Component:  HTTP handling        |                  Version:  dev
     Severity:  Normal               |               Resolution:
     Keywords:                       |             Triage Stage:  Ready for
                                     |  checkin
    Has patch:  1                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Comment (by Mike Edmunds):

 Just a heads-up that `email.Message` would handle some unexpected/invalid
 headers differently from this code. And this code—before and after the
 change—seem to handle them the same as the old cgi.parse_header.

 Example: param without an `=` is ignored by Django (and cgi), but treated
 as having an empty value by `email.Message`:

 {{{
 Python 3.9.24 (main, Oct 28 2025, 09:20:16)
 >>> import cgi
 >>> from email.message import Message
 >>> cgi.parse_header("text/plain; unencoded; filename=file.txt")
 ('text/plain', {'filename': 'file.txt'})
 >>> msg = Message()
 >>> msg["content-type"] = "text/plain; unencoded; filename=file.txt"
 >>> msg.get_params()
 [('text/plain', ''), ('unencoded', ''), ('filename', 'file.txt')]
 }}}

 I'm pretty sure that's invalid, so may not matter much. But if the goal is
 to exactly preserve current behavior there are probably some additional
 test cases to add before trying `email.Message`.
-- 
Ticket URL: <https://code.djangoproject.com/ticket/35440#comment:32>
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 view this discussion visit 
https://groups.google.com/d/msgid/django-updates/0107019d5a7dd401-1318c690-e76c-49e5-b9c9-97c000967ed1-000000%40eu-central-1.amazonses.com.

Reply via email to