Skip to content

Commit

Permalink
Fixing issues in Set::combine() when data or paths used result in emp…
Browse files Browse the repository at this point in the history
…ty datasets. Tests added. Fixes #414
  • Loading branch information
markstory committed Mar 9, 2010
1 parent 348fe6f commit af317a1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
7 changes: 6 additions & 1 deletion cake/libs/set.php
Expand Up @@ -947,6 +947,9 @@ function combine($data, $path1 = null, $path2 = null, $groupPath = null) {
} else {
$keys = Set::extract($data, $path1);
}
if (empty($keys)) {
return array();
}

if (!empty($path2) && is_array($path2)) {
$format = array_shift($path2);
Expand Down Expand Up @@ -978,7 +981,9 @@ function combine($data, $path1 = null, $path2 = null, $groupPath = null) {
return $out;
}
}

if (empty($vals)) {
return array();
}
return array_combine($keys, $vals);
}
/**
Expand Down
3 changes: 3 additions & 0 deletions cake/tests/cases/libs/set.test.php
Expand Up @@ -1621,6 +1621,9 @@ function testCombine() {
$result = Set::combine($b, 'users.{n}.User.id', 'users.{n}.User.non-existant');
$expected = array(2 => null, 14 => null, 25 => null);
$this->assertIdentical($result, $expected);

$result = Set::combine($a, 'fail', 'fail');
$this->assertEqual($result, array());
}
/**
* testMapReverse method
Expand Down

0 comments on commit af317a1

Please sign in to comment.