Allow false/true to be read as keys in Hash::get().

While these are not values within the documented types, there exist use
cases in CakeSession that necessitate these to be supported types.

Refs #10196
This commit is contained in:
mark_story 2017-02-13 21:50:51 -05:00
parent aa8d708b9a
commit 3f10a0227a
2 changed files with 11 additions and 6 deletions

View file

@ -236,10 +236,13 @@ class HashTest extends CakeTestCase {
*/ */
public function testGetEmptyKey() { public function testGetEmptyKey() {
$data = array( $data = array(
'' => 'some value' true => 'true value',
false => 'false value',
'' => 'some value',
); );
$result = Hash::get($data, ''); $this->assertSame($data[''], Hash::get($data, ''));
$this->assertSame($data[''], $result); $this->assertSame($data[false], Hash::get($data, false));
$this->assertSame($data[true], Hash::get($data, true));
} }
/** /**
@ -249,7 +252,7 @@ class HashTest extends CakeTestCase {
* @return void * @return void
*/ */
public function testGetInvalidPath() { public function testGetInvalidPath() {
Hash::get(array('one' => 'two'), true); Hash::get(array('one' => 'two'), new StdClass());
} }
/** /**

View file

@ -48,11 +48,13 @@ class Hash {
} }
if (is_string($path) || is_numeric($path)) { if (is_string($path) || is_numeric($path)) {
$parts = explode('.', $path); $parts = explode('.', $path);
} elseif (is_bool($path) || $path === null) {
$parts = [$path];
} else { } else {
if (!is_array($path)) { if (!is_array($path)) {
throw new InvalidArgumentException(__d('cake_dev', throw new InvalidArgumentException(__d('cake_dev',
'Invalid Parameter %s, should be dot separated path or array.', 'Invalid path parameter: %s, should be dot separated path or array.',
$path var_export($path, true)
)); ));
} }
$parts = $path; $parts = $path;