Skip to content

Commit

Permalink
Fixed Set::extract() where single numeric keys (everything not 0) wer…
Browse files Browse the repository at this point in the history
…e skipped. Fixes #1175

Signed-off-by: mark_story <mark@mark-story.com>
  • Loading branch information
Phally authored and markstory committed Oct 8, 2010
1 parent 16fc261 commit 59b8327
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
4 changes: 2 additions & 2 deletions cake/libs/set.php
Expand Up @@ -390,7 +390,7 @@ function extract($path, $data = null, $options = array()) {
$options = array_merge(array('flatten' => true), $options);
if (!isset($contexts[0])) {
$current = current($data);
if ((is_array($current) && count($data) <= 1) || !is_array($current) || !Set::numeric(array_keys($data))) {
if ((is_array($current) && count($data) < 1) || !is_array($current) || !Set::numeric(array_keys($data))) {
$contexts = array($data);
}
}
Expand Down Expand Up @@ -1127,4 +1127,4 @@ function &get() {
trigger_error('get() is deprecated. Set class should be called statically', E_USER_WARNING);
}
}
?>
?>
23 changes: 22 additions & 1 deletion cake/tests/cases/libs/set.test.php
Expand Up @@ -1127,6 +1127,27 @@ function testExtractWithNonZeroArrays() {
$expected = array(0 => array('Article' => array('id' => 1, 'approved' => 1)));
$result = Set::extract('/Article[approved=1]', $startingAtOne);
$this->assertEqual($result, $expected);

$items = array(
240 => array(
'A' => array(
'field1' => 'a240',
'field2' => 'a240',
),
'B' => array(
'field1' => 'b240',
'field2' => 'b240'
),
)
);

$expected = array(
0 => 'b240'
);

$result = Set::extract('/B/field1', $items);
$this->assertIdentical($result, $expected);
$this->assertIdentical($result, Set::extract('{n}.B.field1', $items));
}
/**
* testExtractWithArrays method
Expand Down Expand Up @@ -2835,4 +2856,4 @@ function testFlatten() {
$this->assertEqual($result, $expected);
}
}
?>
?>

0 comments on commit 59b8327

Please sign in to comment.