Skip to content

Commit

Permalink
Fixing regression in Set::extract(). Refs #1895, #1816, #1692.
Browse files Browse the repository at this point in the history
  • Loading branch information
ADmad committed Aug 13, 2011
1 parent 7983b41 commit b781762
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 8 deletions.
26 changes: 26 additions & 0 deletions lib/Cake/Test/Case/Utility/SetTest.php
Expand Up @@ -991,6 +991,32 @@ public function testExtract() {
);
$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);
}

/**
Expand Down
18 changes: 10 additions & 8 deletions lib/Cake/Utility/Set.php
Expand Up @@ -400,14 +400,9 @@ public static function extract($path, $data = null, $options = array()) {
'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);
Expand Down Expand Up @@ -446,6 +441,13 @@ public static function extract($path, $data = null, $options = array()) {
'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) {
Expand Down

0 comments on commit b781762

Please sign in to comment.