Skip to content

Commit

Permalink
Fixing empty arrays being dropped with Set::sort(). Fixed #67
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Sep 4, 2009
1 parent b5a38d6 commit 4f44111
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cake/libs/set.php
Expand Up @@ -1073,7 +1073,7 @@ function __flatten($results, $key = null) {
if (!is_null($key)) {
$id = $key;
}
if (is_array($r)) {
if (is_array($r) && count($r)) {
$stack = array_merge($stack, Set::__flatten($r, $id));
} else {
$stack[] = array('id' => $id, 'value' => $r);
Expand Down
15 changes: 15 additions & 0 deletions cake/tests/cases/libs/set.test.php
Expand Up @@ -336,6 +336,21 @@ function testSort() {
);
$a = Set::sort($a, '{n}.Person.name', 'ASC');
$this->assertIdentical($a, $b);

$names = array(
array('employees' => array(array('name' => array('first' => 'John', 'last' => 'Doe')))),
array('employees' => array(array('name' => array('first' => 'Jane', 'last' => 'Doe')))),
array('employees' => array(array('name' => array()))),
array('employees' => array(array('name' => array())))
);
$result = Set::sort($names, '{n}.employees.0.name', 'asc', 1);
$expected = array(
array('employees' => array(array('name' => array('first' => 'John', 'last' => 'Doe')))),
array('employees' => array(array('name' => array('first' => 'Jane', 'last' => 'Doe')))),
array('employees' => array(array('name' => array()))),
array('employees' => array(array('name' => array())))
);
$this->assertEqual($result, $expected);
}
/**
* testExtract method
Expand Down

0 comments on commit 4f44111

Please sign in to comment.