Skip to content
Permalink
Browse files

Fix error where multiple files at would be handled incorrectly.

When there are multiple files at the same level the path needs to be
reset on each iteration. Failing to do so causes adjacent files to be
nested incorrectly.
  • Loading branch information...
markstory committed Jul 19, 2014
1 parent 8a2805f commit 57c9ba3f7d1cfdaddff85b27e2b6ec27ffa7b15c
Showing with 27 additions and 10 deletions.
  1. +5 −4 src/Network/Request.php
  2. +22 −6 tests/TestCase/Network/RequestTest.php
@@ -427,17 +427,18 @@ protected function _processFiles($post, $files) {
protected function _processFileData($data, $post, $path = '', $field = '') {
foreach ($post as $key => $fields) {
$newField = $field;
$newPath = $path;
if ($path === '' && $newField === '') {
$newField = $key;
}
if ($field === $newField) {
$path .= '.' . $key;
$newPath .= '.' . $key;
}
if (is_array($fields)) {
$data = $this->_processFileData($data, $fields, $path, $newField);
$data = $this->_processFileData($data, $fields, $newPath, $newField);
} else {
$path = trim($path . '.' . $field, '.');
$data = Hash::insert($data, $path, $fields);
$newPath = trim($newPath . '.' . $field, '.');
$data = Hash::insert($data, $newPath, $fields);
}
}
return $data;
@@ -281,25 +281,31 @@ public function testProcessFilesNested() {
],
'pictures' => [
'name' => [
0 => ['file' => 'a-file.png']
0 => ['file' => 'a-file.png'],
1 => ['file' => 'a-moose.png']
],
'type' => [
0 => ['file' => 'image/png']
0 => ['file' => 'image/png'],
1 => ['file' => 'image/jpg']
],
'tmp_name' => [
0 => ['file' => '/tmp/file123']
0 => ['file' => '/tmp/file123'],
1 => ['file' => '/tmp/file234']
],
'error' => [
0 => ['file' => '0']
0 => ['file' => '0'],
1 => ['file' => '0']
],
'size' => [
0 => ['file' => 17188]
0 => ['file' => 17188],
1 => ['file' => 2010]
],
]
];
$post = [
'pictures' => [
0 => ['name' => 'A cat']
0 => ['name' => 'A cat'],
1 => ['name' => 'A moose']
],
0 => [
'name' => 'A dog'
@@ -326,6 +332,16 @@ public function testProcessFilesNested() {
'error' => '0',
'size' => 17188,
]
],
1 => [
'name' => 'A moose',
'file' => [
'name' => 'a-moose.png',
'type' => 'image/jpg',
'tmp_name' => '/tmp/file234',
'error' => '0',
'size' => 2010,
]
]
],
0 => [

0 comments on commit 57c9ba3

Please sign in to comment.
You can’t perform that action at this time.