Fix closes Issue12529 - cgi.parse_header failure on double quotes and
authorSenthil Kumaran <senthil@uthcode.com>
Wed, 19 Oct 2011 16:52:24 +0000 (00:52 +0800)
committerSenthil Kumaran <senthil@uthcode.com>
Wed, 19 Oct 2011 16:52:24 +0000 (00:52 +0800)
semicolons. Patch by Ben Darnell and Petri Lehtinen.

Lib/cgi.py
Lib/test/test_cgi.py

index b4c620a9e405cbcd1d6e0f66ef8e354d0372a1bc..e7cd7783164a088c032b7baeb2c0c53b6a2d4af4 100755 (executable)
@@ -293,7 +293,7 @@ def _parseparam(s):
     while s[:1] == ';':
         s = s[1:]
         end = s.find(';')
-        while end > 0 and s.count('"', 0, end) % 2:
+        while end > 0 and (s.count('"', 0, end) - s.count('\\"', 0, end)) % 2:
             end = s.find(';', end + 1)
         if end < 0:
             end = len(s)
index e282a51503a4e1bc9eaa2cf0ebe48f2f3dcc96de..63547b24c204efda6b1b83cbbfab344030ac23fa 100644 (file)
@@ -377,6 +377,9 @@ this is the content of the fake file
         self.assertEqual(
             cgi.parse_header('attachment; filename="strange;name";size=123;'),
             ("attachment", {"filename": "strange;name", "size": "123"}))
+        self.assertEqual(
+            cgi.parse_header('form-data; name="files"; filename="fo\\"o;bar"'),
+            ("form-data", {"name": "files", "filename": 'fo"o;bar'}))
 
 
 def test_main():