Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Backport fix for Validation::uploadedFile to 2.x
Don't fail validation when the keys are not the expected order.

Refs #8201
  • Loading branch information
markstory committed Feb 9, 2016
1 parent 80f1844 commit e4b939b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
16 changes: 16 additions & 0 deletions lib/Cake/Test/Case/Utility/ValidationTest.php
Expand Up @@ -2505,4 +2505,20 @@ public function testUploadedFileNoFile() {
);
$this->assertFalse(Validation::uploadedFile($file, $options), 'File is required.');
}
/**
* Test uploaded file validation.
*
* @return void
*/
public function testUploadedFileWithDifferentFileParametersOrder() {
$file = array(
'name' => 'cake.power.gif',
'error' => UPLOAD_ERR_OK,
'tmp_name' => CORE_PATH . 'Cake' . DS . 'Test' . DS . 'test_app' . DS . 'webroot/img/cake.power.gif',
'type' => 'text/plain',
'size' => 201
);
$options = array();
$this->assertTrue(Validation::uploadedFile($file, $options), 'Wrong order');
}
}
3 changes: 2 additions & 1 deletion lib/Cake/Utility/Validation.php
Expand Up @@ -1016,7 +1016,8 @@ public static function uploadedFile($file, $options = array()) {
if (!is_array($file)) {
return false;
}
$keys = array('name', 'tmp_name', 'error', 'type', 'size');
$keys = array('error', 'name', 'size', 'tmp_name', 'type');
ksort($file);
if (array_keys($file) != $keys) {
return false;
}
Expand Down

0 comments on commit e4b939b

Please sign in to comment.