From 85de93a4a7b9e211b19eaa308815e7df0ecb7f97 Mon Sep 17 00:00:00 2001 From: dogmatic69 Date: Fri, 7 Dec 2012 01:26:14 +0000 Subject: [PATCH] fixing issue where merge is renumbering array keys --- lib/Cake/Test/Case/Utility/HashTest.php | 12 ++++++++++++ lib/Cake/Utility/Hash.php | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/Cake/Test/Case/Utility/HashTest.php b/lib/Cake/Test/Case/Utility/HashTest.php index 17b436239..a4bce1bcb 100644 --- a/lib/Cake/Test/Case/Utility/HashTest.php +++ b/lib/Cake/Test/Case/Utility/HashTest.php @@ -2163,6 +2163,18 @@ class HashTest extends CakeTestCase { ) ); $this->assertEquals($result, $expected); + + $data = array('a.b.100.a' => null, 'a.b.200.a' => null); + $expected = array( + 'a' => array( + 'b' => array( + 100 => array('a' => null), + 200 => array('a' => null) + ) + ) + ); + $result = Hash::expand($data); + $this->assertEquals($expected, $result); } } diff --git a/lib/Cake/Utility/Hash.php b/lib/Cake/Utility/Hash.php index 023357692..44ec6755a 100644 --- a/lib/Cake/Utility/Hash.php +++ b/lib/Cake/Utility/Hash.php @@ -596,7 +596,7 @@ class Hash { foreach ((array)$arg as $key => $val) { if (!empty($return[$key]) && is_array($return[$key]) && is_array($val)) { $return[$key] = self::merge($return[$key], $val); - } elseif (is_int($key)) { + } elseif (is_int($key) && isset($return[$key])) { $return[] = $val; } else { $return[$key] = $val;