Use array_key_exists instead of isset()

This allows contains() to work with null values.

Fixes #4083
This commit is contained in:
mark_story 2013-09-19 21:43:59 -04:00
parent 68aefe7eda
commit a30f861f2c
2 changed files with 8 additions and 2 deletions

View file

@ -593,6 +593,12 @@ class HashTest extends CakeTestCase {
); );
$this->assertTrue(Hash::contains($b, $a)); $this->assertTrue(Hash::contains($b, $a));
$this->assertFalse(Hash::contains($a, $b)); $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')));
} }
/** /**

View file

@ -442,14 +442,14 @@ class Hash {
$val = $needle[$key]; $val = $needle[$key];
unset($needle[$key]); unset($needle[$key]);
if (isset($data[$key]) && is_array($val)) { if (array_key_exists($key, $data) && is_array($val)) {
$next = $data[$key]; $next = $data[$key];
unset($data[$key]); unset($data[$key]);
if (!empty($val)) { if (!empty($val)) {
$stack[] = array($val, $next); $stack[] = array($val, $next);
} }
} elseif (!isset($data[$key]) || $data[$key] != $val) { } elseif (!array_key_exists($key, $data) || $data[$key] != $val) {
return false; return false;
} }