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

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

Fixes #3434
This commit is contained in:
Mark Story 2012-12-06 17:44:07 -08:00
commit 6bfbce128f
2 changed files with 13 additions and 1 deletions

View file

@ -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);
}
}

View file

@ -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;