Skip to content
Browse files

Merge pull request #1004 from dogmatic69/hash-expand-integer-key

Fix issue where Hash::expand() sets incorrect array keys

Fixes #3434
  • Loading branch information...
2 parents 00d178f + 85de93a commit 6bfbce128f3b0f33362bfc905a1b87f58fd515fa @markstory markstory committed Dec 6, 2012
Showing with 13 additions and 1 deletion.
  1. +12 −0 lib/Cake/Test/Case/Utility/HashTest.php
  2. +1 −1 lib/Cake/Utility/Hash.php
View
12 lib/Cake/Test/Case/Utility/HashTest.php
@@ -2163,6 +2163,18 @@ public function testExpand() {
)
);
$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);
}
}
View
2 lib/Cake/Utility/Hash.php
@@ -596,7 +596,7 @@ public static function merge(array $data, $merge) {
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;

0 comments on commit 6bfbce1

Please sign in to comment.
Something went wrong with that request. Please try again.