From 8ea2860996328cbfd381e7cdee1111d2c4df6bd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A1chym=20Tou=C5=A1ek?= Date: Wed, 18 Oct 2017 17:59:47 +0200 Subject: [PATCH] [HttpFoundation] Fix FileBag issue with associative arrays --- .../Component/HttpFoundation/FileBag.php | 5 ++++- .../HttpFoundation/Tests/FileBagTest.php | 17 +++++++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Component/HttpFoundation/FileBag.php b/src/Symfony/Component/HttpFoundation/FileBag.php index 722ec2a9c4..41f8c9269f 100644 --- a/src/Symfony/Component/HttpFoundation/FileBag.php +++ b/src/Symfony/Component/HttpFoundation/FileBag.php @@ -87,7 +87,10 @@ class FileBag extends ParameterBag $file = new UploadedFile($file['tmp_name'], $file['name'], $file['type'], $file['size'], $file['error']); } } else { - $file = array_filter(array_map(array($this, 'convertFileInformation'), $file)); + $file = array_map(array($this, 'convertFileInformation'), $file); + if (array_keys($keys) === $keys) { + $file = array_filter($file); + } } } diff --git a/src/Symfony/Component/HttpFoundation/Tests/FileBagTest.php b/src/Symfony/Component/HttpFoundation/Tests/FileBagTest.php index 7d2902d325..b1bbba0d3f 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/FileBagTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/FileBagTest.php @@ -62,7 +62,7 @@ class FileBagTest extends TestCase public function testShouldRemoveEmptyUploadedFilesForMultiUpload() { - $bag = new FileBag(array('file' => array( + $bag = new FileBag(array('files' => array( 'name' => array(''), 'type' => array(''), 'tmp_name' => array(''), @@ -70,7 +70,20 @@ class FileBagTest extends TestCase 'size' => array(0), ))); - $this->assertSame(array(), $bag->get('file')); + $this->assertSame(array(), $bag->get('files')); + } + + public function testShouldNotRemoveEmptyUploadedFilesForAssociativeArray() + { + $bag = new FileBag(array('files' => array( + 'name' => array('file1' => ''), + 'type' => array('file1' => ''), + 'tmp_name' => array('file1' => ''), + 'error' => array('file1' => UPLOAD_ERR_NO_FILE), + 'size' => array('file1' => 0), + ))); + + $this->assertSame(array('file1' => null), $bag->get('files')); } public function testShouldConvertUploadedFilesWithPhpBug()