Permalink
Browse files

Fixing issues in Set::combine() when data or paths used result in emp…

…ty datasets. Tests added. Fixes #414
  • Loading branch information...
1 parent 348fe6f commit af317a107bdb179bce31323d0d28af2c333ebc12 @markstory markstory committed Mar 9, 2010
Showing with 9 additions and 1 deletion.
  1. +6 −1 cake/libs/set.php
  2. +3 −0 cake/tests/cases/libs/set.test.php
View
7 cake/libs/set.php
@@ -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);
@@ -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);
}
/**
View
3 cake/tests/cases/libs/set.test.php
@@ -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

0 comments on commit af317a1

Please sign in to comment.