Browse Source

Allow Set::extract() to match null.

Fixes #2926
mark_story 14 years ago
parent
commit
fb0cc50700
2 changed files with 28 additions and 1 deletions
  1. 27 0
      lib/Cake/Test/Case/Utility/SetTest.php
  2. 1 1
      lib/Cake/Utility/Set.php

+ 27 - 0
lib/Cake/Test/Case/Utility/SetTest.php

@@ -1388,6 +1388,33 @@ class SetTest extends CakeTestCase {
 	}
 
 /**
+ * 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
  *
  * @return void

+ 1 - 1
lib/Cake/Utility/Set.php

@@ -536,7 +536,7 @@ class Set {
 				continue;
 			}
 			list(, $key, $op, $expected) = $match;
-			if (!isset($data[$key])) {
+			if (!(isset($data[$key]) || array_key_exists($key, $data))) {
 				return false;
 			}