diff --git a/lib/Cake/Test/Case/Utility/HashTest.php b/lib/Cake/Test/Case/Utility/HashTest.php index 260568fde..2ed9ffc7d 100644 --- a/lib/Cake/Test/Case/Utility/HashTest.php +++ b/lib/Cake/Test/Case/Utility/HashTest.php @@ -2242,6 +2242,25 @@ class HashTest extends CakeTestCase { $this->assertEquals($input, $result); } +/** + * Tests that nest() returns an empty array for invalid input instead of throwing notices. + * + * @return void + */ + public function testNestInvalid() { + $input = array( + array( + 'ParentCategory' => array( + 'id' => '1', + 'name' => 'Lorem ipsum dolor sit amet', + 'parent_id' => '1' + ) + ) + ); + $result = Hash::nest($input); + $this->assertSame(array(), $result); + } + /** * testMergeDiff method * diff --git a/lib/Cake/Utility/Hash.php b/lib/Cake/Utility/Hash.php index 960ab9af6..f39bf0453 100644 --- a/lib/Cake/Utility/Hash.php +++ b/lib/Cake/Utility/Hash.php @@ -1037,6 +1037,8 @@ class Hash { if ($options['root']) { $root = $options['root']; + } elseif (!$return) { + return array(); } else { $root = self::get($return[0], $parentKeys); }