From 3f10a0227aeaa3d178d6a93fd4a830c52818a4d9 Mon Sep 17 00:00:00 2001 From: mark_story Date: Mon, 13 Feb 2017 21:50:51 -0500 Subject: [PATCH] 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 --- lib/Cake/Test/Case/Utility/HashTest.php | 11 +++++++---- lib/Cake/Utility/Hash.php | 6 ++++-- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/Cake/Test/Case/Utility/HashTest.php b/lib/Cake/Test/Case/Utility/HashTest.php index 53b1d40c8..5618ddc8b 100644 --- a/lib/Cake/Test/Case/Utility/HashTest.php +++ b/lib/Cake/Test/Case/Utility/HashTest.php @@ -236,10 +236,13 @@ class HashTest extends CakeTestCase { */ 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 @@ class HashTest extends CakeTestCase { * @return void */ public function testGetInvalidPath() { - Hash::get(array('one' => 'two'), true); + Hash::get(array('one' => 'two'), new StdClass()); } /** diff --git a/lib/Cake/Utility/Hash.php b/lib/Cake/Utility/Hash.php index 2ca530ece..af7a098eb 100644 --- a/lib/Cake/Utility/Hash.php +++ b/lib/Cake/Utility/Hash.php @@ -48,11 +48,13 @@ class Hash { } 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;