diff --git a/lib/Cake/Test/Case/Utility/SetTest.php b/lib/Cake/Test/Case/Utility/SetTest.php index a0f0042cc..9476cc43f 100644 --- a/lib/Cake/Test/Case/Utility/SetTest.php +++ b/lib/Cake/Test/Case/Utility/SetTest.php @@ -991,6 +991,32 @@ class SetTest extends CakeTestCase { ); $result = Set::extract('/Category[id=1]/..', $data); $this->assertEqual($expected, $result); + + $data = array( + array( + 'ChildNode' => array('id' => 1), + array('name' => 'Item 1') + ), + array( + 'ChildNode' => array('id' => 2), + array('name' => 'Item 2') + ), + ); + + $expected = array( + 'Item 1', + 'Item 2' + ); + $result = Set::extract('/0/name', $data); + $this->assertEqual($expected, $result); + + $data = array( + array('A1', 'B1'), + array('A2', 'B2') + ); + $expected = array('A1', 'A2'); + $result = Set::extract('/0', $data); + $this->assertEqual($expected, $result); } /** diff --git a/lib/Cake/Utility/Set.php b/lib/Cake/Utility/Set.php index b93b4e18f..f5527dd58 100644 --- a/lib/Cake/Utility/Set.php +++ b/lib/Cake/Utility/Set.php @@ -400,14 +400,9 @@ class Set { 'key' => $key, 'item' => array_keys($context['item']), ); - } elseif (($key === $token || (ctype_digit($token) && $key == $token) || $token === '.')) { - $context['trace'][] = $key; - $matches[] = array( - 'trace' => $context['trace'], - 'key' => $key, - 'item' => $context['item'], - ); - } elseif (is_array($context['item']) && array_key_exists($token, $context['item'])) { + } elseif (is_array($context['item']) + && array_key_exists($token, $context['item']) + && !(strval($key) === strval($token) && count($tokens) == 1 && $tokens[0] === '.')) { $items = $context['item'][$token]; if (!is_array($items)) { $items = array($items); @@ -446,6 +441,13 @@ class Set { 'item' => $item, ); } + } elseif ($key === $token || (ctype_digit($token) && $key == $token) || $token === '.') { + $context['trace'][] = $key; + $matches[] = array( + 'trace' => $context['trace'], + 'key' => $key, + 'item' => $context['item'], + ); } } if ($conditions) {