Browse Source

Merge pull request #4704 from HavokInspiration/hash-remove-fix

Fix Hash::remove() removing data even if the path is not matched
Mark Story 11 years ago
parent
commit
d7c4d3b521
2 changed files with 13 additions and 1 deletions
  1. 12 0
      lib/Cake/Test/Case/Utility/HashTest.php
  2. 1 1
      lib/Cake/Utility/Hash.php

+ 12 - 0
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);
 	}
 
 /**

+ 1 - 1
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]);
 			}
 		}