From a30f861f2c53b888f41fe9242138f0e1e3147466 Mon Sep 17 00:00:00 2001 From: mark_story Date: Thu, 19 Sep 2013 21:43:59 -0400 Subject: [PATCH] Use array_key_exists instead of isset() This allows contains() to work with null values. Fixes #4083 --- lib/Cake/Test/Case/Utility/HashTest.php | 6 ++++++ lib/Cake/Utility/Hash.php | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/Cake/Test/Case/Utility/HashTest.php b/lib/Cake/Test/Case/Utility/HashTest.php index 67adfc9db..ebfa9c520 100644 --- a/lib/Cake/Test/Case/Utility/HashTest.php +++ b/lib/Cake/Test/Case/Utility/HashTest.php @@ -593,6 +593,12 @@ class HashTest extends CakeTestCase { ); $this->assertTrue(Hash::contains($b, $a)); $this->assertFalse(Hash::contains($a, $b)); + + $a = array(0 => 'test', 'string' => null); + $this->assertTrue(Hash::contains($a, array('string' => null))); + + $a = array(0 => 'test', 'string' => null); + $this->assertTrue(Hash::contains($a, array('test'))); } /** diff --git a/lib/Cake/Utility/Hash.php b/lib/Cake/Utility/Hash.php index 8cc99977a..e12f14c5f 100644 --- a/lib/Cake/Utility/Hash.php +++ b/lib/Cake/Utility/Hash.php @@ -442,14 +442,14 @@ class Hash { $val = $needle[$key]; unset($needle[$key]); - if (isset($data[$key]) && is_array($val)) { + if (array_key_exists($key, $data) && is_array($val)) { $next = $data[$key]; unset($data[$key]); if (!empty($val)) { $stack[] = array($val, $next); } - } elseif (!isset($data[$key]) || $data[$key] != $val) { + } elseif (!array_key_exists($key, $data) || $data[$key] != $val) { return false; }