Browse Source

Fix wrong dimensions when the first element is false.

yutmr 9 years ago
parent
commit
072d8cf837
2 changed files with 8 additions and 1 deletions
  1. 1 1
      src/Utility/Hash.php
  2. 7 0
      tests/TestCase/Utility/HashTest.php

+ 1 - 1
src/Utility/Hash.php

@@ -837,7 +837,7 @@ class Hash
     public static function maxDimensions(array $data)
     {
         $depth = [];
-        if (is_array($data) && reset($data) !== false) {
+        if (is_array($data) && !empty($data)) {
             foreach ($data as $value) {
                 if (is_array($value)) {
                     $depth[] = static::maxDimensions($value) + 1;

+ 7 - 0
tests/TestCase/Utility/HashTest.php

@@ -506,6 +506,13 @@ class HashTest extends TestCase
         ];
         $result = Hash::maxDimensions($data);
         $this->assertEquals($result, 5);
+
+        $data = [
+           '1' => false,
+           '2' => ['2.1' => '2.1.1']
+        ];
+        $result = Hash::maxDimensions($data);
+        $this->assertEquals($result, 2);
     }
 
     /**