Browse Source

Don't filter out 0.0 in Hash::filter()

Refs #10385
Mark Story 9 years ago
parent
commit
dc8cefce9f
2 changed files with 16 additions and 3 deletions
  1. 1 1
      src/Utility/Hash.php
  2. 15 2
      tests/TestCase/Utility/HashTest.php

+ 1 - 1
src/Utility/Hash.php

@@ -646,7 +646,7 @@ class Hash
      */
      */
     protected static function _filter($var)
     protected static function _filter($var)
     {
     {
-        return $var === 0 || $var === '0' || !empty($var);
+        return $var === 0 || $var === 0.0 || $var === '0' || !empty($var);
     }
     }
 
 
     /**
     /**

+ 15 - 2
tests/TestCase/Utility/HashTest.php

@@ -857,8 +857,21 @@ class HashTest extends TestCase
      */
      */
     public function testFilter()
     public function testFilter()
     {
     {
-        $result = Hash::filter(['0', false, true, 0, ['one thing', 'I can tell you', 'is you got to be', false]]);
-        $expected = ['0', 2 => true, 3 => 0, 4 => ['one thing', 'I can tell you', 'is you got to be']];
+        $result = Hash::filter([
+            '0',
+            false,
+            true,
+            0,
+            0.0,
+            ['one thing', 'I can tell you', 'is you got to be', false]
+        ]);
+        $expected = [
+            0 => '0',
+            2 => true,
+            3 => 0,
+            4 => 0.0,
+            5 => ['one thing', 'I can tell you', 'is you got to be']
+        ];
         $this->assertSame($expected, $result);
         $this->assertSame($expected, $result);
 
 
         $result = Hash::filter([1, [false]]);
         $result = Hash::filter([1, [false]]);