Browse Source

check for file param order

antograssiot 11 years ago
parent
commit
60f60c7814
2 changed files with 20 additions and 1 deletions
  1. 2 1
      src/Validation/Validation.php
  2. 18 0
      tests/TestCase/Validation/ValidationTest.php

+ 2 - 1
src/Validation/Validation.php

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

+ 18 - 0
tests/TestCase/Validation/ValidationTest.php

@@ -2447,4 +2447,22 @@ class ValidationTest extends TestCase {
 		$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');
+	}
+
+
 }