@@ -790,6 +790,54 @@ public function testUploadTooManyFilesReturnsTruncatedList()
790790 $ this ->assertSame ('hello ' , (string )$ file ->getStream ());
791791 }
792792
793+ public function testUploadTooManyFilesIgnoresEmptyFilesAndIncludesThemDespiteTruncatedList ()
794+ {
795+ $ boundary = "---------------------------12758086162038677464950549563 " ;
796+
797+ $ data = "-- $ boundary \r\n" ;
798+ $ data .= "Content-Disposition: form-data; name= \"first \"; filename= \"first \"\r\n" ;
799+ $ data .= "Content-type: text/plain \r\n" ;
800+ $ data .= "\r\n" ;
801+ $ data .= "hello \r\n" ;
802+ $ data .= "-- $ boundary \r\n" ;
803+ $ data .= "Content-Disposition: form-data; name= \"empty \"; filename= \"\"\r\n" ;
804+ $ data .= "Content-type: text/plain \r\n" ;
805+ $ data .= "\r\n" ;
806+ $ data .= "\r\n" ;
807+ $ data .= "-- $ boundary \r\n" ;
808+ $ data .= "Content-Disposition: form-data; name= \"second \"; filename= \"second \"\r\n" ;
809+ $ data .= "Content-type: text/plain \r\n" ;
810+ $ data .= "\r\n" ;
811+ $ data .= "world \r\n" ;
812+ $ data .= "-- $ boundary-- \r\n" ;
813+
814+ $ request = new ServerRequest ('POST ' , 'http://example.com/ ' , array (
815+ 'Content-Type ' => 'multipart/form-data; boundary= ' . $ boundary ,
816+ ), $ data , 1.1 );
817+
818+ $ parser = new MultipartParser (100 , 1 );
819+ $ parsedRequest = $ parser ->parse ($ request );
820+
821+ $ files = $ parsedRequest ->getUploadedFiles ();
822+
823+ $ this ->assertCount (2 , $ files );
824+ $ this ->assertTrue (isset ($ files ['first ' ]));
825+ $ this ->assertTrue (isset ($ files ['empty ' ]));
826+
827+ $ file = $ files ['first ' ];
828+ $ this ->assertSame ('first ' , $ file ->getClientFilename ());
829+ $ this ->assertSame ('text/plain ' , $ file ->getClientMediaType ());
830+ $ this ->assertSame (5 , $ file ->getSize ());
831+ $ this ->assertSame (UPLOAD_ERR_OK , $ file ->getError ());
832+ $ this ->assertSame ('hello ' , (string )$ file ->getStream ());
833+
834+ $ file = $ files ['empty ' ];
835+ $ this ->assertSame ('' , $ file ->getClientFilename ());
836+ $ this ->assertSame ('text/plain ' , $ file ->getClientMediaType ());
837+ $ this ->assertSame (0 , $ file ->getSize ());
838+ $ this ->assertSame (UPLOAD_ERR_NO_FILE , $ file ->getError ());
839+ }
840+
793841 public function testPostMaxFileSize ()
794842 {
795843 $ boundary = "---------------------------12758086162038677464950549563 " ;
0 commit comments