Fixing regression in Set::extract(). Closes #1895 #1816 #1692

This commit is contained in:
ADmad 2011-08-10 03:56:45 +05:30
parent 6ef4ce4c31
commit 392102b71f
2 changed files with 38 additions and 10 deletions

View file

@ -431,14 +431,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);
@ -477,6 +472,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) {

View file

@ -973,6 +973,32 @@ class SetTest extends CakeTestCase {
);
$result = Set::extract('/Category[id=1]/..', $data);
$this->assertEqual($result, $expected);
$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($result, $expected);
$data = array(
array('A1', 'B1'),
array('A2', 'B2')
);
$expected = array('A1', 'A2');
$result = Set::extract('/0', $data);
$this->assertEqual($result, $expected);
}
/**