Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Allow Set::extract() to match null.
Fixes #2926
  • Loading branch information
markstory committed May 31, 2012
1 parent 25c7a27 commit fb0cc50
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
27 changes: 27 additions & 0 deletions lib/Cake/Test/Case/Utility/SetTest.php
Expand Up @@ -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
*
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/Utility/Set.php
Expand Up @@ -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;
}

Expand Down

0 comments on commit fb0cc50

Please sign in to comment.