Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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

  • Loading branch information...
commit b781762903db0815eb0df55cb558210bf7aeebde 1 parent 7983b41
@ADmad ADmad authored
Showing with 36 additions and 8 deletions.
  1. +26 −0 lib/Cake/Test/Case/Utility/SetTest.php
  2. +10 −8 lib/Cake/Utility/Set.php
View
26 lib/Cake/Test/Case/Utility/SetTest.php
@@ -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);
}
/**
View
18 lib/Cake/Utility/Set.php
@@ -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);
@@ -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) {
Please sign in to comment.
Something went wrong with that request. Please try again.