Backport fix for Validation::uploadedFile to 2.x

Don't fail validation when the keys are not the expected order.

Refs #8201
This commit is contained in:
mark_story 2016-02-08 22:37:25 -05:00
parent 80f18448b5
commit e4b939bba0
2 changed files with 18 additions and 1 deletions

View file

@ -2505,4 +2505,20 @@ class ValidationTest extends CakeTestCase {
);
$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');
}
}

View file

@ -1016,7 +1016,8 @@ class Validation {
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;
}