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

Commit 320ea38

Browse files
committed
Merge branch 'hotfix/57'
Close #57 Fixes #56
2 parents 5183448 + fb56a62 commit 320ea38

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ All notable changes to this project will be documented in this file, in reverse
2424
- [#51](https://github.com/zendframework/zend-diactoros/pull/51) fixes
2525
`MessageTrait::getHeaderLine()` to return an empty string instead of `null` if
2626
the header is undefined (which is the behavior specified in PSR-7).
27+
- [#57](https://github.com/zendframework/zend-diactoros/pull/57) fixes the
28+
behavior of how the `ServerRequestFactory` marshals upload files when they are
29+
represented as a nested associative array.
2730

2831
## 1.0.3 - 2015-06-04
2932

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: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,4 +415,23 @@ public function testNormalizeServerReturnsArrayUnalteredIfApacheHeadersDoNotCont
415415

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

0 commit comments

Comments
 (0)