mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-19 02:56:15 +00:00
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:
parent
3a561986f1
commit
90ad813b40
2 changed files with 8 additions and 1 deletions
|
@ -1367,6 +1367,13 @@ class HashTest extends CakeTestCase {
|
||||||
'pages' => array('name' => array()),
|
'pages' => array('name' => array()),
|
||||||
);
|
);
|
||||||
$this->assertEquals($expected, $result);
|
$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'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -290,7 +290,7 @@ class Hash {
|
||||||
$count = count($path);
|
$count = count($path);
|
||||||
$last = $count - 1;
|
$last = $count - 1;
|
||||||
foreach ($path as $i => $key) {
|
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;
|
$key = (int)$key;
|
||||||
}
|
}
|
||||||
if ($op === 'insert') {
|
if ($op === 'insert') {
|
||||||
|
|
Loading…
Add table
Reference in a new issue