Skip to content
Permalink
Browse files

Fix sorting empty data with Hash & Set.

Fixes #3420
  • Loading branch information...
markstory committed Nov 30, 2012
1 parent f250592 commit 889c1ebc09ca3dfe829cb57ac518ebc8af24d335
@@ -928,6 +928,9 @@ public function testExtractUnevenKeys() {
* @return void
*/
public function testSort() {
$result = Hash::sort(array(), '{n}.name', 'asc');
$this->assertEquals(array(), $result);
$a = array(
0 => array(
'Person' => array('name' => 'Jeff'),
@@ -225,6 +225,9 @@ public function testMerge() {
* @return void
*/
public function testSort() {
$result = Set::sort(array(), '{n}.name', 'asc');
$this->assertEquals(array(), $result);
$a = array(
0 => array('Person' => array('name' => 'Jeff'), 'Friend' => array(array('name' => 'Nate'))),
1 => array('Person' => array('name' => 'Tracy'),'Friend' => array(array('name' => 'Lindsay')))
@@ -730,6 +730,9 @@ public static function apply(array $data, $path, $function) {
* @link http://book.cakephp.org/2.0/en/core-utility-libraries/hash.html#Hash::sort
*/
public static function sort(array $data, $path, $dir, $type = 'regular') {
if (empty($data)) {
return array();
}
$originalKeys = array_keys($data);
$numeric = is_numeric(implode('', $originalKeys));
if ($numeric) {
@@ -956,6 +956,9 @@ protected static function _flatten($results, $key = null) {
* @link http://book.cakephp.org/2.0/en/core-utility-libraries/set.html#Set::sort
*/
public static function sort($data, $path, $dir) {
if (empty($data)) {
return $data;
}
$originalKeys = array_keys($data);
$numeric = false;
if (is_numeric(implode('', $originalKeys))) {

2 comments on commit 889c1eb

@steffann

This comment has been minimized.

Copy link

steffann replied Nov 30, 2012

Thank you for the quick solution!

@markstory

This comment has been minimized.

Copy link
Member Author

markstory replied Dec 1, 2012

Welcome 👍

Please sign in to comment.
You can’t perform that action at this time.