diff --git a/cake/libs/set.php b/cake/libs/set.php index d48adc7de7f..5e80f46b231 100644 --- a/cake/libs/set.php +++ b/cake/libs/set.php @@ -386,7 +386,10 @@ function extract($path, $data = null, $options = array()) { $contexts = $data; $options = array_merge(array('flatten' => true), $options); if (!isset($contexts[0])) { - $contexts = array($data); + $current = current($data); + if ((is_array($current) && count($data) <= 1) || !is_array($current)) { + $contexts = array($data); + } } $tokens = array_slice(preg_split('/(?assertEqual($r, $expected); + $nonZero = array( + 1 => array( + 'User' => array( + 'id' => 1, + 'name' => 'John', + ) + ), + 2 => array( + 'User' => array( + 'id' => 2, + 'name' => 'Bob', + ) + ), + 3 => array( + 'User' => array( + 'id' => 3, + 'name' => 'Tony', + ) + ) + ); + $expected = array(1, 2, 3); + $r = Set::extract('/User/id', $nonZero); + $this->assertEqual($r, $expected); + $common = array( array( 'Article' => array( @@ -969,7 +993,6 @@ function testExtract() { $expected = array(array('name' => 'zipfile.zip','type' => 'application/zip','tmp_name' => '/tmp/php178.tmp','error' => 0,'size' => '564647')); $r = Set::extract('/file/.[type=application/zip]', $f); $this->assertEqual($r, $expected); - } /** * testMatches method @@ -2396,7 +2419,7 @@ function testXmlSetReverse() { array( 'Item' => array( 'title' => 'An example of a correctly reversed XMLNode', - 'Desc' => array(), + 'desc' => array(), ) ) );