1 Fixes Python CGI being confused about binary files (bugs 31546357 & 31936635).
4 https://bugs.python.org/issue27777
6 WIP patch taken from upstream is still buggy, so we use
7 this in-house developed one.
9 --- Python-3.7.10/Lib/cgi.py
10 +++ Python-3.7.10/Lib/cgi.py
11 @@ -711,7 +711,10 @@ class FieldStorage:
15 - self.file.write(data)
16 + if self._binary_file:
17 + self.file.write(data)
19 + self.file.write(data.decode())
20 todo = todo - len(data)
23 --- Python-3.7.10/Lib/test/test_cgi.py
24 +++ Python-3.7.10/Lib/test/test_cgi.py
25 @@ -396,6 +396,18 @@ Larry
26 self.assertEqual(fs.list[0].name, 'submit-name')
27 self.assertEqual(fs.list[0].value, 'Larry')
29 + def test_content_length_no_content_disposition(self):
30 + body = b'{"test":123}'
32 + 'CONTENT_LENGTH': len(body),
33 + 'REQUEST_METHOD': 'POST',
34 + 'CONTENT_TYPE': 'application/json',
35 + 'wsgi.input': BytesIO(body),
38 + form = cgi.FieldStorage(fp=env['wsgi.input'], environ=env)
39 + self.assertEqual(form.file.read(), body.decode(form.encoding))
41 def test_field_storage_multipart_no_content_length(self):
42 fp = BytesIO(b"""--MyBoundary
43 Content-Disposition: form-data; name="my-arg"; filename="foo"