From b70cb132fd1ac50f429cdc8ce68f0303e40c6051 Mon Sep 17 00:00:00 2001 From: Yves Date: Tue, 23 Sep 2014 22:00:49 +0200 Subject: [PATCH] Fix Hash::remove() removing data even if the path is not matched --- lib/Cake/Test/Case/Utility/HashTest.php | 12 ++++++++++++ lib/Cake/Utility/Hash.php | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/Cake/Test/Case/Utility/HashTest.php b/lib/Cake/Test/Case/Utility/HashTest.php index dfc3c59c8..159b27a89 100644 --- a/lib/Cake/Test/Case/Utility/HashTest.php +++ b/lib/Cake/Test/Case/Utility/HashTest.php @@ -1488,6 +1488,18 @@ class HashTest extends CakeTestCase { ) ); $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); } /** diff --git a/lib/Cake/Utility/Hash.php b/lib/Cake/Utility/Hash.php index f88365b74..6cb5c05d4 100644 --- a/lib/Cake/Utility/Hash.php +++ b/lib/Cake/Utility/Hash.php @@ -355,7 +355,7 @@ class Hash { if (empty($data[$k])) { unset($data[$k]); } - } elseif ($match) { + } elseif ($match && empty($nextPath)) { unset($data[$k]); } }