diff --git a/cake/libs/set.php b/cake/libs/set.php index 55b8c9f7a..f7fc08be7 100644 --- a/cake/libs/set.php +++ b/cake/libs/set.php @@ -423,7 +423,7 @@ class Set extends Object { $matches[] = $context; continue; } - + $match = false; if (array_key_exists($token, $context['item'])) { $items = $context['item'][$token]; @@ -441,7 +441,7 @@ class Set extends Object { 'item' => $item, ); } - } else if ($key === $token && (!$conditions || Set::matches($conditions, $context['item'], $i+1))) { + } elseif (($key === $token || (ctype_digit($token) && $key == $token) || $token === '.') && (!$conditions || Set::matches($conditions, $context['item'], $i))) { $matches[] = array( 'trace' => am($context['trace'], $key), 'key' => $key, @@ -457,7 +457,7 @@ class Set extends Object { $r = array(); foreach ($matches as $match) { - if (!$options['flatten'] || is_array($match['item'])) { + if ((!$options['flatten'] || is_array($match['item'])) && !is_int($match['key'])) { $r[] = array($match['key'] => $match['item']); } else { $r[] = $match['item']; diff --git a/cake/tests/cases/libs/set.test.php b/cake/tests/cases/libs/set.test.php index 202a401d5..ee5fbf878 100644 --- a/cake/tests/cases/libs/set.test.php +++ b/cake/tests/cases/libs/set.test.php @@ -494,6 +494,18 @@ class SetTest extends UnitTestCase { $expected = array(1, 2, 4, 5); $r = Set::extract($common, '/Comment[id!=3]/id'); $this->assertEqual($r, $expected); + + $expected = array($common[0]['Comment'][2]); + $r = Set::extract($common, '/Comment/2'); + $this->assertEqual($r, $expected); + + $expected = array($common[0]['Comment'][1]); + $r = Set::extract($common, '/Comment[1]/.[id=2]'); + $this->assertEqual($r, $expected); + + $expected = array($common[0]['Comment'][1]); + $r = Set::extract($common, '/Comment[1]/.[2]'); + $this->assertEqual($r, $expected); } /** * undocumented function