Skip to content
Permalink
Browse files

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
  • Loading branch information...
markstory committed Feb 14, 2017
1 parent aa8d708 commit 3f10a0227aeaa3d178d6a93fd4a830c52818a4d9
Showing with 11 additions and 6 deletions.
  1. +7 −4 lib/Cake/Test/Case/Utility/HashTest.php
  2. +4 −2 lib/Cake/Utility/Hash.php
@@ -236,10 +236,13 @@ public function testGet() {
*/
public function testGetEmptyKey() {
$data = array(
'' => 'some value'
true => 'true value',
false => 'false value',
'' => 'some value',
);
$result = Hash::get($data, '');
$this->assertSame($data[''], $result);
$this->assertSame($data[''], Hash::get($data, ''));
$this->assertSame($data[false], Hash::get($data, false));
$this->assertSame($data[true], Hash::get($data, true));
}
/**
@@ -249,7 +252,7 @@ public function testGetEmptyKey() {
* @return void
*/
public function testGetInvalidPath() {
Hash::get(array('one' => 'two'), true);
Hash::get(array('one' => 'two'), new StdClass());
}
/**
@@ -48,11 +48,13 @@ public static function get(array $data, $path, $default = null) {
}
if (is_string($path) || is_numeric($path)) {
$parts = explode('.', $path);
} elseif (is_bool($path) || $path === null) {
$parts = [$path];
} else {
if (!is_array($path)) {
throw new InvalidArgumentException(__d('cake_dev',
'Invalid Parameter %s, should be dot separated path or array.',
$path
'Invalid path parameter: %s, should be dot separated path or array.',
var_export($path, true)
));
}
$parts = $path;

0 comments on commit 3f10a02

Please sign in to comment.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.