Skip to content
This repository was archived by the owner on Jan 29, 2020. It is now read-only.

Commit 6de02cb

Browse files
committed
Merge pull request #57 from jonhudson/master
File validation fails when file contains sub-arrays
2 parents 5183448 + 77f4cec commit 6de02cb

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/ServerRequestFactory.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,7 @@ private static function createUploadedFileFromSpec(array $value)
469469
*/
470470
private static function normalizeNestedFileSpec(array $files = [])
471471
{
472+
$normalizedFiles = [];
472473
foreach (array_keys($files['tmp_name']) as $key) {
473474
$spec = [
474475
'tmp_name' => $files['tmp_name'][$key],
@@ -477,8 +478,8 @@ private static function normalizeNestedFileSpec(array $files = [])
477478
'name' => $files['name'][$key],
478479
'type' => $files['type'][$key],
479480
];
480-
$files[$key] = self::createUploadedFileFromSpec($spec);
481+
$normalizedFiles[$key] = self::createUploadedFileFromSpec($spec);
481482
}
482-
return $files;
483+
return $normalizedFiles;
483484
}
484485
}

test/ServerRequestFactoryTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,4 +415,19 @@ public function testNormalizeServerReturnsArrayUnalteredIfApacheHeadersDoNotCont
415415

416416
$this->assertEquals($expected, $server);
417417
}
418+
419+
public function testNormalizeFilesReturnsOnlyActualFilesWhenOriginalFilesContainsNestedArrays()
420+
{
421+
$files = [ 'fooFiles' => [
422+
'tmp_name' => ['file' => 'php://temp'],
423+
'size' => ['file' => 0],
424+
'error' => ['file' => 0],
425+
'name' => ['file' => 'foo.bar'],
426+
'type' => ['file' => 'text/plain'],
427+
]];
428+
429+
$normalizedFiles = ServerRequestFactory::normalizeFiles($files);
430+
431+
$this->assertCount(1, $normalizedFiles['fooFiles']);
432+
}
418433
}

0 commit comments

Comments
 (0)