summaryrefslogtreecommitdiff
path: root/Lib/cgi.py
diff options
context:
space:
mode:
authorFred Drake <fdrake@acm.org>2008-12-04 18:25:17 +0000
committerFred Drake <fdrake@acm.org>2008-12-04 18:25:17 +0000
commit5248103ef910774628639c767b8fbcf88684e013 (patch)
tree3315c3c67992985436549fc2efe16cdb6a09b38f /Lib/cgi.py
parented2f42377571f95993b4c79c7d1382eeda12acfd (diff)
downloadcpython-git-5248103ef910774628639c767b8fbcf88684e013.tar.gz
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 33b91bfbd2..0bb5b8eaf1 100755
--- a/Lib/cgi.py
+++ b/Lib/cgi.py
@@ -289,16 +289,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()