diff --git a/lib/Cake/Test/Case/Utility/HashTest.php b/lib/Cake/Test/Case/Utility/HashTest.php index d4d3c94d5..40fcd7b54 100644 --- a/lib/Cake/Test/Case/Utility/HashTest.php +++ b/lib/Cake/Test/Case/Utility/HashTest.php @@ -846,6 +846,29 @@ class HashTest extends CakeTestCase { $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 = Hash::extract($data, 'Country.{n}[name=/Canada|^$/]'); + $expected = array( + array( + 'name' => 'Canada', + ), + array( + 'name' => null, + ), + ); + $this->assertEquals($expected, $result); + } + /** * Test that uneven keys are handled correctly. * diff --git a/lib/Cake/Utility/Hash.php b/lib/Cake/Utility/Hash.php index 638ddc20e..bfbcffaf5 100644 --- a/lib/Cake/Utility/Hash.php +++ b/lib/Cake/Utility/Hash.php @@ -192,7 +192,7 @@ class Hash { } // Empty attribute = fail. - if (!isset($data[$attr])) { + if (!(isset($data[$attr]) || array_key_exists($attr, $data))) { return false; }