Skip to content

Commit

Permalink
Fix file array parsing for flat file arrays.
Browse files Browse the repository at this point in the history
The file array parsing was not correct when handling flat file arrays.
When dealing with flat arrays we don't need to munge data nearly as
much.

Fixes #3364
  • Loading branch information
markstory committed Apr 22, 2014
1 parent 0fca336 commit bc245b1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 17 deletions.
10 changes: 6 additions & 4 deletions src/Network/Request.php
@@ -1,7 +1,5 @@
<?php
/**
* Request
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
Expand Down Expand Up @@ -386,7 +384,7 @@ protected static function _base() {
* @return array merged post + file data.
*/
protected function _processFiles($post, $files) {
if (isset($files) && is_array($files)) {
if (is_array($files)) {
foreach ($files as $key => $data) {
if (!is_numeric($key)) {
$this->_processFileData($post, '', $data, $key);
Expand Down Expand Up @@ -417,7 +415,11 @@ protected function _processFileData(&$post, $path, $data, $field) {
if (is_array($fields)) {
$this->_processFileData($post, $newPath, $fields, $field);
} else {
$newPath .= '.' . $field;
if (strpos($newPath, '.') === false) {
$newPath = $field . '.' . $key;
} else {
$newPath .= '.' . $field;
}
$post = Hash::insert($post, $newPath, $fields);
}
}
Expand Down
33 changes: 20 additions & 13 deletions tests/TestCase/Network/RequestTest.php
@@ -1,7 +1,5 @@
<?php
/**
* CakeRequest Test case file.
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
Expand Down Expand Up @@ -490,25 +488,34 @@ public function testFilesParsing() {
)
);
$this->assertEquals($expected, $request->data);
}

$files = array(
'name' => array('birth_cert' => 'born on.txt'),
'type' => array('birth_cert' => 'application/octet-stream'),
'tmp_name' => array('birth_cert' => '/private/var/tmp/phpbsUWfH'),
'error' => array('birth_cert' => 0),
'size' => array('birth_cert' => 123)
);
/**
* Test processing a file input with no .'s in it.
*
* @return void
*/
public function testProcessFilesFlat() {
$files = [
'birth_cert' => [
'name' => 'born on.txt',
'type' => 'application/octet-stream',
'tmp_name' => '/private/var/tmp/phpbsUWfH',
'error' => 0,
'size' => 123,
]
];

$request = new Request(compact('files'));
$expected = array(
'birth_cert' => array(
$expected = [
'birth_cert' => [
'name' => 'born on.txt',
'type' => 'application/octet-stream',
'tmp_name' => '/private/var/tmp/phpbsUWfH',
'error' => 0,
'size' => 123
)
);
]
];
$this->assertEquals($expected, $request->data);
}

Expand Down

0 comments on commit bc245b1

Please sign in to comment.