Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

You should be able to regex match null/''

Fixes #2926
  • Loading branch information...
commit 01b3135a637fea4f2125dae2cbef671c1bd18b84 1 parent 9a8ceae
@markstory markstory authored
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;
}
Please sign in to comment.
Something went wrong with that request. Please try again.