Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1ef0c03

Browse files
committed
3.2 - Fix closes Issue12529 - cgi.parse_header failure on double quotes and
semicolons. Patch by Ben Darnell and Petri Lehtinen.
1 parent e130a52 commit 1ef0c03

2 files changed

Lines changed: 5 additions & 1 deletion

File tree

Lib/cgi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ def _parseparam(s):
291291
while s[:1] == ';':
292292
s = s[1:]
293293
end = s.find(';')
294-
while end > 0 and s.count('"', 0, end) % 2:
294+
while end > 0 and (s.count('"', 0, end) - s.count('\\"', 0, end)) % 2:
295295
end = s.find(';', end + 1)
296296
if end < 0:
297297
end = len(s)

Lib/test/test_cgi.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,10 @@ def test_parse_header(self):
348348
self.assertEqual(
349349
cgi.parse_header('attachment; filename="strange;name";size=123;'),
350350
("attachment", {"filename": "strange;name", "size": "123"}))
351+
self.assertEqual(
352+
cgi.parse_header('form-data; name="files"; filename="fo\\"o;bar"'),
353+
("form-data", {"name": "files", "filename": 'fo"o;bar'}))
354+
351355

352356
BOUNDARY = "---------------------------721837373350705526688164684"
353357

0 commit comments

Comments
 (0)