Skip to content

Commit

Permalink
Merge pull request #4567 from antograssiot/#4563
Browse files Browse the repository at this point in the history
3.0 - Check for `$file` array order in `uploadedFile()`
  • Loading branch information
lorenzo committed Sep 10, 2014
2 parents 42345cc + 60f60c7 commit b60031b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Validation/Validation.php
Expand Up @@ -983,7 +983,8 @@ public static function uploadedFile($file, $options = []) {
if (!is_array($file)) {
return false;
}
$keys = ['name', 'tmp_name', 'error', 'type', 'size'];
$keys = ['error', 'name', 'size', 'tmp_name', 'type'];
ksort($file);
if (array_keys($file) != $keys) {
return false;
}
Expand Down
18 changes: 18 additions & 0 deletions tests/TestCase/Validation/ValidationTest.php
Expand Up @@ -2447,4 +2447,22 @@ public function testUploadedFileNoFile() {
$this->assertFalse(Validation::uploadedFile($file, $options), 'File is required.');
}

/**
* Test uploaded file validation.
*
* @return void
*/
public function testUploadedFileWithDifferentFileParametersOrder() {
$file = [
'name' => 'cake.power.gif',
'error' => UPLOAD_ERR_OK,
'tmp_name' => TEST_APP . 'webroot/img/cake.power.gif',
'type' => 'text/plain',
'size' => 201
];
$options = [];
$this->assertTrue(Validation::uploadedFile($file, $options), 'Wrong order');
}


}

0 comments on commit b60031b

Please sign in to comment.