diff --git a/cake/libs/set.php b/cake/libs/set.php index 9b90a5951..7b8e0d7db 100644 --- a/cake/libs/set.php +++ b/cake/libs/set.php @@ -389,7 +389,7 @@ class Set { $options = array_merge(array('flatten' => true), $options); if (!isset($contexts[0])) { $current = current($data); - if ((is_array($current) && count($data) <= 1) || !is_array($current) || !Set::numeric(array_keys($data))) { + if ((is_array($current) && count($data) < 1) || !is_array($current) || !Set::numeric(array_keys($data))) { $contexts = array($data); } } diff --git a/cake/tests/cases/libs/set.test.php b/cake/tests/cases/libs/set.test.php index a6518155e..ba5b21a07 100644 --- a/cake/tests/cases/libs/set.test.php +++ b/cake/tests/cases/libs/set.test.php @@ -1132,6 +1132,27 @@ class SetTest extends CakeTestCase { $expected = array(0 => array('Article' => array('id' => 1, 'approved' => 1))); $result = Set::extract('/Article[approved=1]', $startingAtOne); $this->assertEqual($result, $expected); + + $items = array( + 240 => array( + 'A' => array( + 'field1' => 'a240', + 'field2' => 'a240', + ), + 'B' => array( + 'field1' => 'b240', + 'field2' => 'b240' + ), + ) + ); + + $expected = array( + 0 => 'b240' + ); + + $result = Set::extract('/B/field1', $items); + $this->assertIdentical($result, $expected); + $this->assertIdentical($result, Set::extract('{n}.B.field1', $items)); } /** * testExtractWithArrays method