multipart 2.0.0__tar.gz → 2.0.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {multipart-2.0.0 → multipart-2.0.1}/PKG-INFO +1 -1
- {multipart-2.0.0 → multipart-2.0.1}/multipart.py +8 -4
- {multipart-2.0.0 → multipart-2.0.1}/test/test_push_parser.py +30 -0
- {multipart-2.0.0 → multipart-2.0.1}/test/test_wsgi_parser.py +13 -0
- {multipart-2.0.0 → multipart-2.0.1}/CHANGELOG.rst +0 -0
- {multipart-2.0.0 → multipart-2.0.1}/LICENSE +0 -0
- {multipart-2.0.0 → multipart-2.0.1}/MAINTAINERS.rst +0 -0
- {multipart-2.0.0 → multipart-2.0.1}/README.rst +0 -0
- {multipart-2.0.0 → multipart-2.0.1}/pyproject.toml +0 -0
- {multipart-2.0.0 → multipart-2.0.1}/test/__init__.py +0 -0
- {multipart-2.0.0 → multipart-2.0.1}/test/__main__.py +0 -0
- {multipart-2.0.0 → multipart-2.0.1}/test/test_header_utils.py +0 -0
- {multipart-2.0.0 → multipart-2.0.1}/test/test_legacy_parser.py +0 -0
- {multipart-2.0.0 → multipart-2.0.1}/test/test_multdict.py +0 -0
- {multipart-2.0.0 → multipart-2.0.1}/test/utils.py +0 -0
|
@@ -11,7 +11,7 @@ License: MIT (see LICENSE file)
|
|
|
11
11
|
"""
|
|
12
12
|
|
|
13
13
|
__author__ = "Marcel Hellkamp"
|
|
14
|
-
__version__ = '2.0.
|
|
14
|
+
__version__ = '2.0.1'
|
|
15
15
|
__license__ = "MIT"
|
|
16
16
|
__all__ = [
|
|
17
17
|
"MultipartError",
|
|
@@ -733,8 +733,10 @@ class PushMultipartParser:
|
|
|
733
733
|
if line[0] in b" \t": # Multi-line header value
|
|
734
734
|
if not self._segment_headerlist or self.strict:
|
|
735
735
|
raise StrictParserError("Unexpected segment header continuation")
|
|
736
|
+
if line.isspace():
|
|
737
|
+
raise StrictParserError("Empty segment header continuation")
|
|
736
738
|
prev = ": ".join(self._segment_headerlist.pop())
|
|
737
|
-
line = prev.encode(self.header_charset) + b" " + line
|
|
739
|
+
line = prev.encode(self.header_charset) + b" " + line[1:]
|
|
738
740
|
|
|
739
741
|
# Enforce header limits
|
|
740
742
|
if len(line) > self.max_header_size:
|
|
@@ -753,7 +755,7 @@ class PushMultipartParser:
|
|
|
753
755
|
name = name.strip().title()
|
|
754
756
|
if name not in _KNOWN_HEADERS and not _re_hname.fullmatch(name):
|
|
755
757
|
raise ParserError("Invalid segment header name")
|
|
756
|
-
value = value.
|
|
758
|
+
value = value.lstrip(" \t")
|
|
757
759
|
|
|
758
760
|
if name == "Content-Length":
|
|
759
761
|
if self._segment_limit >= 0:
|
|
@@ -1264,7 +1266,9 @@ def parse_form_data(
|
|
|
1264
1266
|
if not boundary:
|
|
1265
1267
|
raise ParserError("Missing boundary for multipart/form-data")
|
|
1266
1268
|
|
|
1267
|
-
for part in MultipartParser(
|
|
1269
|
+
for part in MultipartParser(
|
|
1270
|
+
stream, boundary, content_length, strict=strict, **kwargs
|
|
1271
|
+
):
|
|
1268
1272
|
if part.filename or not part.is_buffered():
|
|
1269
1273
|
files.append(part.name, part)
|
|
1270
1274
|
else: # TODO: Big form-fields go into the files dict. Really?
|
|
@@ -241,6 +241,36 @@ class TestPushParser(PushTestBase):
|
|
|
241
241
|
with self.assertParseError("Maximum segment header length exceeded"):
|
|
242
242
|
self.parse(b"\tmoooooooooooooooooooooooooore value\r\n")
|
|
243
243
|
|
|
244
|
+
def test_header_continuation_empty(self):
|
|
245
|
+
self.reset(max_header_size=64)
|
|
246
|
+
self.parse(b"--boundary\r\n")
|
|
247
|
+
self.parse(b"Content-Disposition: form-data; name=foo\r\n")
|
|
248
|
+
with self.assertRaises(multipart.StrictParserError):
|
|
249
|
+
self.parse(b" \r\n")
|
|
250
|
+
|
|
251
|
+
def test_header_continuation_unicode_whitespace_only(self):
|
|
252
|
+
self.reset(max_header_size=64)
|
|
253
|
+
self.parse(b"--boundary\r\n")
|
|
254
|
+
self.parse(b"Content-Disposition: form-data; name=foo\r\n")
|
|
255
|
+
with self.assertRaises(multipart.StrictParserError):
|
|
256
|
+
self.parse(b" \r\n")
|
|
257
|
+
|
|
258
|
+
def test_header_continuation_long_whitespace_padded(self):
|
|
259
|
+
self.reset(max_header_size=64)
|
|
260
|
+
self.parse(b"--boundary\r\n")
|
|
261
|
+
self.parse(b"Content-Disposition: form-data; name=foo\r\n")
|
|
262
|
+
with self.assertRaises(multipart.ParserLimitReached):
|
|
263
|
+
self.parse(b" " * 65 + b"value\r\n")
|
|
264
|
+
|
|
265
|
+
def test_header_continuation_many_unicode_whitespace(self):
|
|
266
|
+
self.reset(max_header_size=64)
|
|
267
|
+
self.parse(b"--boundary\r\n")
|
|
268
|
+
self.parse(b"Content-Disposition: form-data; name=foo\r\n")
|
|
269
|
+
# This bypasses the strict whitespace-only checks inside continuation
|
|
270
|
+
# logic which operate on bytes, but should still hit the header size limit.
|
|
271
|
+
with self.assertRaises(multipart.ParserLimitReached):
|
|
272
|
+
self.parse(b" \xc2\xa0\r\n" * 32)
|
|
273
|
+
|
|
244
274
|
def test_header_no_colon(self):
|
|
245
275
|
with self.assertParseError("Malformed segment header"):
|
|
246
276
|
self.parse(b"--boundary\r\nno-colon\r\n\r\ndata\r\n--boundary--")
|
|
@@ -26,6 +26,19 @@ class TestFormParser(BaseParserTest):
|
|
|
26
26
|
self.assertEqual(files['file1'].name, 'file1')
|
|
27
27
|
self.assertEqual(files['file1'].content_type, 'image/png')
|
|
28
28
|
|
|
29
|
+
def test_multipart_strict_passed_to_parser(self):
|
|
30
|
+
self.write(
|
|
31
|
+
"--foo\r\n",
|
|
32
|
+
"Content-Disposition: form-data;\r\n", # no name
|
|
33
|
+
'\tname="text1"\r\n',
|
|
34
|
+
"\r\n",
|
|
35
|
+
"abc",
|
|
36
|
+
"\r\n--foo--",
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
with self.assertRaises(multipart.StrictParserError):
|
|
40
|
+
self.parse_form_data(strict=True)
|
|
41
|
+
|
|
29
42
|
def test_empty(self):
|
|
30
43
|
self.write_end()
|
|
31
44
|
forms, files = self.parse_form_data()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|