diff --git a/lib/Cake/Test/Case/Utility/SetTest.php b/lib/Cake/Test/Case/Utility/SetTest.php index 293ee85763e..1c2c0f1d57c 100644 --- a/lib/Cake/Test/Case/Utility/SetTest.php +++ b/lib/Cake/Test/Case/Utility/SetTest.php @@ -1387,6 +1387,33 @@ public function testExtractWithNonArrayElements() { $this->assertEquals($expected, $result); } +/** + * Test that extract() + matching can hit null things. + */ + public function testExtractMatchesNull() { + $data = array( + 'Country' => array( + array('name' => 'Canada'), + array('name' => 'Australia'), + array('name' => null), + ) + ); + $result = Set::extract('/Country[name=/Canada|^$/]', $data); + $expected = array( + array( + 'Country' => array( + 'name' => 'Canada', + ), + ), + array( + 'Country' => array( + 'name' => null, + ), + ), + ); + $this->assertEquals($expected, $result); + } + /** * testMatches method * diff --git a/lib/Cake/Utility/Set.php b/lib/Cake/Utility/Set.php index 430824274dc..a240d3e34a6 100644 --- a/lib/Cake/Utility/Set.php +++ b/lib/Cake/Utility/Set.php @@ -536,7 +536,7 @@ public static function matches($conditions, $data = array(), $i = null, $length continue; } list(, $key, $op, $expected) = $match; - if (!isset($data[$key])) { + if (!(isset($data[$key]) || array_key_exists($key, $data))) { return false; }