summaryrefslogtreecommitdiffstats
path: root/Lib/cgi.py
diff options
context:
space:
mode:
authorFred Drake <fdrake@acm.org>2008-12-04 19:24:50 (GMT)
committerFred Drake <fdrake@acm.org>2008-12-04 19:24:50 (GMT)
commit9a0a65b524fa5afa91d918977bada03d24f95234 (patch)
tree37c46791a36fe961a93c3a6e0aa9462de21590da /Lib/cgi.py
parentc47408acc10f13869ba18bbbc311276fab24ce18 (diff)
downloadcpython-9a0a65b524fa5afa91d918977bada03d24f95234.zip
cpython-9a0a65b524fa5afa91d918977bada03d24f95234.tar.gz
cpython-9a0a65b524fa5afa91d918977bada03d24f95234.tar.bz2
Merged revisions 67528 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r67528 | fred.drake | 2008-12-04 13:25:17 -0500 (Thu, 04 Dec 2008) | 4 lines Issue #1055234: cgi.parse_header(): Fixed parsing of header parameters to support unusual filenames (such as those containing semi-colons) in Content-Disposition headers. ........
Diffstat (limited to 'Lib/cgi.py')
-rwxr-xr-xLib/cgi.py18
1 files changed, 15 insertions, 3 deletions
diff --git a/Lib/cgi.py b/Lib/cgi.py
index e62fcf2..35f6996 100755
--- a/Lib/cgi.py
+++ b/Lib/cgi.py
@@ -272,16 +272,28 @@ def parse_multipart(fp, pdict):
return partdict
+def _parseparam(s):
+ while s[:1] == ';':
+ s = s[1:]
+ end = s.find(';')
+ while end > 0 and 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:]
+
def parse_header(line):
"""Parse a Content-type like header.
Return the main content-type and a dictionary of options.
"""
- plist = [x.strip() for x in line.split(';')]
- key = plist.pop(0).lower()
+ parts = _parseparam(';' + line)
+ key = parts.__next__()
pdict = {}
- for p in plist:
+ for p in parts:
i = p.find('=')
if i >= 0:
name = p[:i].strip().lower()