Allow Set::extract() to match null.

Fixes #2926
This commit is contained in:
mark_story 2012-05-30 21:19:38 -04:00
parent 25c7a27495
commit fb0cc50700
2 changed files with 28 additions and 1 deletions

View file

@ -1387,6 +1387,33 @@ class SetTest 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 = Set::extract('/Country[name=/Canada|^$/]', $data);
$expected = array(
array(
'Country' => array(
'name' => 'Canada',
),
),
array(
'Country' => array(
'name' => null,
),
),
);
$this->assertEquals($expected, $result);
}
/**
* testMatches method
*

View file

@ -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;
}