Skip to content

Commit

Permalink
Fix Hash::remove() removing data even if the path is not matched
Browse files Browse the repository at this point in the history
  • Loading branch information
HavokInspiration committed Sep 23, 2014
1 parent d715c6f commit b70cb13
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
12 changes: 12 additions & 0 deletions lib/Cake/Test/Case/Utility/HashTest.php
Expand Up @@ -1488,6 +1488,18 @@ public function testRemove() {
)
);
$this->assertEquals($expected, $result);

$array = array(
0 => 'foo',
1 => array(
0 => 'baz'
)
);
$expected = $array;
$result = Hash::remove($array, '{n}.part');
$this->assertEquals($expected, $result);
$result = Hash::remove($array, '{n}.{n}.part');
$this->assertEquals($expected, $result);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/Utility/Hash.php
Expand Up @@ -355,7 +355,7 @@ public static function remove(array $data, $path) {
if (empty($data[$k])) {
unset($data[$k]);
}
} elseif ($match) {
} elseif ($match && empty($nextPath)) {
unset($data[$k]);
}
}
Expand Down

0 comments on commit b70cb13

Please sign in to comment.