@@ -825,7 +825,7 @@ def test_http(self, param: TestParams) -> None:
825
825
return
826
826
827
827
# No error!
828
- self .assertEqual (processed , len (param ["test" ]))
828
+ self .assertEqual (processed , len (param ["test" ]), param [ "name" ] )
829
829
830
830
# Assert that the parser gave us the appropriate fields/files.
831
831
for e in param ["result" ]["expected" ]:
@@ -1210,6 +1210,44 @@ def on_field(f: FieldProtocol) -> None:
1210
1210
self .assertEqual (fields [2 ].field_name , b"baz" )
1211
1211
self .assertEqual (fields [2 ].value , b"asdf" )
1212
1212
1213
+ def test_multipart_parser_newlines_before_first_boundary (self ) -> None :
1214
+ """This test makes sure that the parser does not handle when there is junk data after the last boundary."""
1215
+ num = 5_000_000
1216
+ data = (
1217
+ "\r \n " * num + "--boundary\r \n "
1218
+ 'Content-Disposition: form-data; name="file"; filename="filename.txt"\r \n '
1219
+ "Content-Type: text/plain\r \n \r \n "
1220
+ "hello\r \n "
1221
+ "--boundary--"
1222
+ )
1223
+
1224
+ files : list [File ] = []
1225
+
1226
+ def on_file (f : FileProtocol ) -> None :
1227
+ files .append (cast (File , f ))
1228
+
1229
+ f = FormParser ("multipart/form-data" , on_field = Mock (), on_file = on_file , boundary = "boundary" )
1230
+ f .write (data .encode ("latin-1" ))
1231
+
1232
+ def test_multipart_parser_data_after_last_boundary (self ) -> None :
1233
+ """This test makes sure that the parser does not handle when there is junk data after the last boundary."""
1234
+ num = 50_000_000
1235
+ data = (
1236
+ "--boundary\r \n "
1237
+ 'Content-Disposition: form-data; name="file"; filename="filename.txt"\r \n '
1238
+ "Content-Type: text/plain\r \n \r \n "
1239
+ "hello\r \n "
1240
+ "--boundary--" + "-" * num + "\r \n "
1241
+ )
1242
+
1243
+ files : list [File ] = []
1244
+
1245
+ def on_file (f : FileProtocol ) -> None :
1246
+ files .append (cast (File , f ))
1247
+
1248
+ f = FormParser ("multipart/form-data" , on_field = Mock (), on_file = on_file , boundary = "boundary" )
1249
+ f .write (data .encode ("latin-1" ))
1250
+
1213
1251
def test_max_size_multipart (self ) -> None :
1214
1252
# Load test data.
1215
1253
test_file = "single_field_single_file.http"
0 commit comments