You should be able to regex match null/''

Fixes #2926
This commit is contained in:
mark_story 2012-05-30 21:28:18 -04:00
parent 9a8ceaeba6
commit 01b3135a63
2 changed files with 24 additions and 1 deletions

View file

@ -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.
*

View file

@ -192,7 +192,7 @@ class Hash {
}
// Empty attribute = fail.
if (!isset($data[$attr])) {
if (!(isset($data[$attr]) || array_key_exists($attr, $data))) {
return false;
}