[issue12529] cgi.parse_header fails on double quotes and semicolons

Ben Darnell report at bugs.python.org
Sun Jul 10 22:56:05 CEST 2011


New submission from Ben Darnell <ben.darnell at gmail.com>:

cgi.parse_header doesn't work on headers that contain combinations of double quotes and semicolons (although it works with either type of character individually).  

>>> cgi.parse_header('form-data; name="files"; filename="fo\\"o;bar"')
('form-data', {'name': 'files', 'filename': '"fo\\"o'})

This issue is present in python 2.7 and 3.2.  One solution is to change _parseparam as follows (same as email.message._parseparam):

def _parseparam(s):
    while s[:1] == ';':
        s = s[1:]
        end = s.find(';')
        while end > 0 and (s.count('"', 0, end) - s.count('\\"', 0, end)) % 2:
            end = s.find(';', end + 1)
        if end < 0:
            end = len(s)
        f = s[:end]
        yield f.strip()
        s = s[end:]

----------
messages: 140091
nosy: Ben.Darnell
priority: normal
severity: normal
status: open
title: cgi.parse_header fails on double quotes and semicolons

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue12529>
_______________________________________


More information about the Python-bugs-list mailing list