8000 [HttpFoundation] Fix file upload multiple with no files · symfony/symfony@d111996 · GitHub
[go: up one dir, main page]

Skip to content

Commit d111996

Browse files
committed
[HttpFoundation] Fix file upload multiple with no files
1 parent 86eb10c commit d111996

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/Symfony/Component/HttpFoundation/FileBag.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public function add(array $files = array())
6969
*
7070
* @param array|UploadedFile $file A (multi-dimensional) array of uploaded file information
7171
*
72-
* @return UploadedFile|UploadedFile[] A (multi-dimensional) array of UploadedFile instances
72+
* @return UploadedFile[]|UploadedFile|null A (multi-dimensional) array of UploadedFile instances
7373
*/
7474
protected function convertFileInformation($file)
7575
{
@@ -89,7 +89,7 @@ protected function convertFileInformation($file)
8989
$file = new UploadedFile($file['tmp_name'], $file['name'], $file['type'], $file['size'], $file['error']);
9090
}
9191
} else {
92-
$file = array_map(array($this, 'convertFileInformation'), $file);
92+
$file = array_filter(array_map(array($this, 'convertFileInformation'), $file));
9393
}
9494
}
9595

src/Symfony/Component/HttpFoundation/Tests/FileBagTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,19 @@ public function testShouldSetEmptyUploadedFilesToNull()
6060
$this->assertNull($bag->get('file'));
6161
}
6262

63+
public function testShouldRemoveEmptyUploadedFilesForMultiUpload()
64+
{
65+
$bag = new FileBag(array('file' => array(
66+
'name' => array(''),
67+
'type' => array(''),
68+
'tmp_name' => array(''),
69+
'error' => array(UPLOAD_ERR_NO_FILE),
70+
'size' => array(0),
71+
)));
72+
73+
$this->assertSame([], $bag->get('file'));
74+
}
75+
6376
public function testShouldConvertUploadedFilesWithPhpBug()
6477
{
6578
$tmpFile = $this->createTempFile();

0 commit comments

Comments
 (0)
0