Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 748223c

Browse filesBrowse files
committed
[HttpFoundation] Fix file upload multiple with no files
1 parent 86eb10c commit 748223c
Copy full SHA for 748223c

File tree

2 files changed

+15
-2
lines changed
Filter options

2 files changed

+15
-2
lines changed

‎src/Symfony/Component/HttpFoundation/FileBag.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/FileBag.php
+2-2Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/Tests/FileBagTest.php
+13Lines 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(array(), $bag->get('file'));
74+
}
75+
6376
public function testShouldConvertUploadedFilesWithPhpBug()
6477
{
6578
$tmpFile = $this->createTempFile();

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.