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

This commit is contained in:
ADmad 2011-08-10 03:56:45 +05:30
parent 7983b4109b
commit b781762903
2 changed files with 36 additions and 8 deletions

View file

@ -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);
}
/**

View file

@ -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) {