From fb0cc50700f90df4a7f92c0d7fe15d03ed444aaf Mon Sep 17 00:00:00 2001 From: mark_story Date: Wed, 30 May 2012 21:19:38 -0400 Subject: [PATCH] Allow Set::extract() to match null. Fixes #2926 --- lib/Cake/Test/Case/Utility/SetTest.php | 27 ++++++++++++++++++++++++++ lib/Cake/Utility/Set.php | 2 +- 2 files changed, 28 insertions(+), 1 deletion(-) 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; }