Browse files

You should be able to regex match null/''

Fixes #2926
  • Loading branch information...
1 parent 9a8ceae commit 01b3135a637fea4f2125dae2cbef671c1bd18b84 @markstory markstory committed May 30, 2012
Showing with 24 additions and 1 deletion.
  1. +23 −0 lib/Cake/Test/Case/Utility/HashTest.php
  2. +1 −1 lib/Cake/Utility/Hash.php
View
23 lib/Cake/Test/Case/Utility/HashTest.php
@@ -847,6 +847,29 @@ public function testExtractAttributePattern() {
}
/**
+ * 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.
*
* @return void
View
2 lib/Cake/Utility/Hash.php
@@ -192,7 +192,7 @@ protected static function _matches(array $data, $selector) {
}
// Empty attribute = fail.
- if (!isset($data[$attr])) {
+ if (!(isset($data[$attr]) || array_key_exists($attr, $data))) {
return false;
}

0 comments on commit 01b3135

Please sign in to comment.