Permalink
Browse files

ensure path parameter behavior consistency for Hash insert and remove…

… methods
  • Loading branch information...
Shiyanov Sergey
Shiyanov Sergey committed Jul 23, 2015
1 parent 7d7ab3e commit 8c15ee9fd31f84088ae7f88d4a9e9c3b2121f2e2
Showing with 21 additions and 4 deletions.
  1. +10 −4 src/Utility/Hash.php
  2. +11 −0 tests/TestCase/Utility/HashTest.php
View
@@ -390,11 +390,17 @@ public static function remove(array $data, $path)
foreach ($data as $k => $v) {
$match = static::_matchToken($k, $token);
if ($match && is_array($v)) {
if ($conditions && static::_matches($v, $conditions)) {
unset($data[$k]);
continue;
if ($conditions) {
if (static::_matches($v, $conditions)) {
if ($nextPath) {
$data[$k] = static::remove($v, $nextPath);
} else {
unset($data[$k]);
}
}
} else {
$data[$k] = static::remove($v, $nextPath);
}
$data[$k] = static::remove($v, $nextPath);
if (empty($data[$k])) {
unset($data[$k]);
}
@@ -1617,6 +1617,17 @@ public function testRemoveMulti()
4 => ['Item' => ['id' => 5, 'title' => 'fifth']],
];
$this->assertEquals($expected, $result);
$data[3]['testable'] = true;
$result = Hash::remove($data, '{n}[testable].Item[id=/\b2|\b4/].title');
$expected = [
0 => ['Item' => ['id' => 1, 'title' => 'first']],
1 => ['Item' => ['id' => 2, 'title' => 'second']],
2 => ['Item' => ['id' => 3, 'title' => 'third']],
3 => ['Item' => ['id' => 4], 'testable' => true],
4 => ['Item' => ['id' => 5, 'title' => 'fifth']],
];
$this->assertEquals($expected, $result);
}
/**

0 comments on commit 8c15ee9

Please sign in to comment.