Skip to content
Permalink
Browse files

Hash::nest() should throw an exception instead of returning an empty …

…array

Refs: #3498 (comment)
  • Loading branch information...
ravage84 committed Jul 8, 2014
1 parent e410501 commit c321a8fa9354e48626fde7dedda83fd62b24fee3
Showing with 10 additions and 5 deletions.
  1. +3 −3 lib/Cake/Test/Case/Utility/HashTest.php
  2. +7 −2 lib/Cake/Utility/Hash.php
@@ -2277,8 +2277,9 @@ public function testMissingParent() {
}
/**
* Tests that nest() returns an empty array for invalid input instead of throwing notices.
* Tests that nest() throws an InvalidArgumentException when providing an invalid input.
*
* @expectedException InvalidArgumentException
* @return void
*/
public function testNestInvalid() {
@@ -2291,8 +2292,7 @@ public function testNestInvalid() {
)
)
);
$result = Hash::nest($input);
$this->assertSame(array(), $result);
Hash::nest($input);
}
/**
@@ -1006,6 +1006,7 @@ public static function normalize(array $data, $assoc = true) {
* @param array $options Options are:
* @return array of results, nested
* @see Hash::extract()
* @throws InvalidArgumentException When providing invalid data.
* @link http://book.cakephp.org/2.0/en/core-utility-libraries/hash.html#Hash::nest
*/
public static function nest(array $data, $options = array()) {
@@ -1048,10 +1049,14 @@ public static function nest(array $data, $options = array()) {
}
}
if (!$return) {
throw new InvalidArgumentException(__d('cake_dev',
'Invalid data array to nest.'
));
}
if ($options['root']) {
$root = $options['root'];
} elseif (!$return) {
return array();
} else {
$root = self::get($return[0], $parentKeys);
}

0 comments on commit c321a8f

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