Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

…ty datasets. Tests added. Fixes #414
  • Loading branch information...
commit af317a107bdb179bce31323d0d28af2c333ebc12 1 parent 348fe6f
@markstory markstory authored
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
Please sign in to comment.
Something went wrong with that request. Please try again.