Skip to content
This repository
Browse code

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
Mark Story authored March 08, 2010
7  cake/libs/set.php
@@ -947,6 +947,9 @@ function combine($data, $path1 = null, $path2 = null, $groupPath = null) {
947 947
 		} else {
948 948
 			$keys = Set::extract($data, $path1);
949 949
 		}
  950
+		if (empty($keys)) {
  951
+			return array();
  952
+		}
950 953
 
951 954
 		if (!empty($path2) && is_array($path2)) {
952 955
 			$format = array_shift($path2);
@@ -978,7 +981,9 @@ function combine($data, $path1 = null, $path2 = null, $groupPath = null) {
978 981
 				return $out;
979 982
 			}
980 983
 		}
981  
-
  984
+		if (empty($vals)) {
  985
+			return array();
  986
+		}
982 987
 		return array_combine($keys, $vals);
983 988
 	}
984 989
 /**
3  cake/tests/cases/libs/set.test.php
@@ -1621,6 +1621,9 @@ function testCombine() {
1621 1621
 		$result = Set::combine($b, 'users.{n}.User.id', 'users.{n}.User.non-existant');
1622 1622
 		$expected = array(2 => null, 14 => null, 25 => null);
1623 1623
 		$this->assertIdentical($result, $expected);
  1624
+
  1625
+		$result = Set::combine($a, 'fail', 'fail');
  1626
+		$this->assertEqual($result, array());
1624 1627
 	}
1625 1628
 /**
1626 1629
  * testMapReverse method

0 notes on commit af317a1

Please sign in to comment.
Something went wrong with that request. Please try again.