Browse Source

Merge pull request #4927 from cakephp/issue-4924

Allow float 0 to be considered empty.
José Lorenzo Rodríguez 11 years ago
parent
commit
f9aaec93ed
2 changed files with 4 additions and 1 deletions
  1. 1 1
      src/Validation/Validator.php
  2. 3 0
      tests/TestCase/Validation/ValidatorTest.php

+ 1 - 1
src/Validation/Validator.php

@@ -481,7 +481,7 @@ class Validator implements \ArrayAccess, \IteratorAggregate, \Countable {
  * @return bool
  */
 	protected function _fieldIsEmpty($data) {
-		if (empty($data) && $data !== '0' && $data !== false && $data !== 0) {
+		if (empty($data) && $data !== '0' && $data !== false && $data !== 0 && $data !== 0.0) {
 			return true;
 		}
 		return false;

+ 3 - 0
tests/TestCase/Validation/ValidatorTest.php

@@ -373,6 +373,9 @@ class ValidatorTest extends TestCase {
 		$errors = $validator->errors(['title' => 0]);
 		$this->assertEmpty($errors);
 
+		$errors = $validator->errors(['title' => 0.0]);
+		$this->assertEmpty($errors);
+
 		$errors = $validator->errors(['title' => '0']);
 		$this->assertEmpty($errors);