Skip to content

Commit

Permalink
Merge pull request #4927 from cakephp/issue-4924
Browse files Browse the repository at this point in the history
Allow float 0 to be considered empty.
  • Loading branch information
lorenzo committed Oct 19, 2014
2 parents 760dd50 + 7d398ee commit f9aaec9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Validation/Validator.php
Expand Up @@ -481,7 +481,7 @@ protected function _canBeEmpty($field, $context) {
* @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;
Expand Down
3 changes: 3 additions & 0 deletions tests/TestCase/Validation/ValidatorTest.php
Expand Up @@ -373,6 +373,9 @@ public function testErrorsWithEmptyAllowed() {
$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);

Expand Down

0 comments on commit f9aaec9

Please sign in to comment.