Fix Hash not returning correct value with special paths

When doing a Hash::insert() with a part of the path starting with a '0', Hash::get() returned null even if the same path was used.
This commit is contained in:
Yves 2014-09-10 22:47:25 +02:00
parent 3a561986f1
commit 90ad813b40
2 changed files with 8 additions and 1 deletions

View file

@ -1367,6 +1367,13 @@ class HashTest extends CakeTestCase {
'pages' => array('name' => array()),
);
$this->assertEquals($expected, $result);
$a = array(
'foo' => array('bar' => 'baz')
);
$result = Hash::insert($a, 'some.0123.path', array('foo' => array('bar' => 'baz')));
$expected = array('foo' => array('bar' => 'baz'));
$this->assertEquals($expected, Hash::get($result, 'some.0123.path'));
}
/**

View file

@ -290,7 +290,7 @@ class Hash {
$count = count($path);
$last = $count - 1;
foreach ($path as $i => $key) {
if (is_numeric($key) && (int)$key > 0 || $key === '0') {
if ((is_numeric($key) && intval($key) > 0 || $key === '0') && strpos($key, '0') !== 0) {
$key = (int)$key;
}
if ($op === 'insert') {