File tree Expand file tree Collapse file tree 2 files changed +31
-4
lines changed Expand file tree Collapse file tree 2 files changed +31
-4
lines changed Original file line number Diff line number Diff line change @@ -721,11 +721,10 @@ def parse_boundary_stream(stream, max_header_size):
721
721
722
722
# Eliminate blank lines
723
723
for line in header .split (b"\r \n " ):
724
- # This terminology ("main value" and "dictionary of
725
- # parameters") is from the Python docs.
726
724
try :
727
- main_value_pair , params = parse_header_parameters (line .decode ())
728
- name , value = main_value_pair .split (":" , 1 )
725
+ name , value_with_params = line .decode ().split (":" , 1 )
726
+ name = name .lower ().rstrip (" " )
727
+ value , params = parse_header_parameters (value_with_params .lstrip (" " ))
729
728
params = {k : v .encode () for k , v in params .items ()}
730
729
except ValueError : # Invalid header.
731
730
continue
Original file line number Diff line number Diff line change @@ -450,6 +450,34 @@ def test_body_after_POST_multipart_form_data(self):
450
450
with self .assertRaises (RawPostDataException ):
451
451
request .body
452
452
453
+ def test_malformed_multipart_header (self ):
454
+ for header in [
455
+ 'Content-Disposition : form-data; name="name"' ,
456
+ 'Content-Disposition:form-data; name="name"' ,
457
+ 'Content-Disposition :form-data; name="name"' ,
458
+ ]:
459
+ with self .subTest (header ):
460
+ payload = FakePayload (
461
+ "\r \n " .join (
462
+ [
463
+ "--boundary" ,
464
+ header ,
465
+ "" ,
466
+ "value" ,
467
+ "--boundary--" ,
468
+ ]
469
+ )
470
+ )
471
+ request = WSGIRequest (
472
+ {
473
+ "REQUEST_METHOD" : "POST" ,
474
+ "CONTENT_TYPE" : "multipart/form-data; boundary=boundary" ,
475
+ "CONTENT_LENGTH" : len (payload ),
476
+ "wsgi.input" : payload ,
477
+ }
478
+ )
479
+ self .assertEqual (request .POST , {"name" : ["value" ]})
480
+
453
481
def test_body_after_POST_multipart_related (self ):
454
482
"""
455
483
Reading body after parsing multipart that isn't form-data is allowed
You can’t perform that action at this time.
0 commit comments