From: Sebastian Michaelsen Date: Tue, 11 Dec 2012 10:43:57 +0000 (+0100) Subject: [BUGFIX] array_merge_recursive_overrule: __UNSET for array values X-Git-Tag: TYPO3_6-1-0alpha1~174 X-Git-Url: http://git.typo3.org/Packages/TYPO3.CMS.git/commitdiff_plain/c0defbe74e3992b07dce859024d51544c4c7b9ed?hp=f57b442c1cf70d0b727bf1f7b79cf46e4b11d8d6;ds=sidebyside [BUGFIX] array_merge_recursive_overrule: __UNSET for array values Using __UNSET on keys that hold array values does not unset them. However the documentation does not mention this restriction. Therefore this is considered a bug and fixed by this patch. Resolves: #43874 Releases: 6.1, 6.0, 4.7 Change-Id: Ie9f96c6f608da7e91fec2bc639dba9f3bcc8f426 Reviewed-on: https://review.typo3.org/17096 Reviewed-by: Markus Klein Reviewed-by: Wouter Wolters Reviewed-by: Tobias Liebig Tested-by: Tobias Liebig --- diff --git a/typo3/sysext/core/Classes/Utility/GeneralUtility.php b/typo3/sysext/core/Classes/Utility/GeneralUtility.php index d61029905a85..abeb964179d8 100644 --- a/typo3/sysext/core/Classes/Utility/GeneralUtility.php +++ b/typo3/sysext/core/Classes/Utility/GeneralUtility.php @@ -1630,16 +1630,19 @@ class GeneralUtility { */ static public function array_merge_recursive_overrule(array $arr0, array $arr1, $notAddKeys = FALSE, $includeEmptyValues = TRUE, $enableUnsetFeature = TRUE) { foreach ($arr1 as $key => $val) { + if ($enableUnsetFeature && $val === '__UNSET') { + unset($arr0[$key]); + continue; + } if (is_array($arr0[$key])) { if (is_array($arr1[$key])) { $arr0[$key] = self::array_merge_recursive_overrule($arr0[$key], $arr1[$key], $notAddKeys, $includeEmptyValues, $enableUnsetFeature); } - } elseif (!$notAddKeys || isset($arr0[$key])) { - if ($enableUnsetFeature && $val === '__UNSET') { - unset($arr0[$key]); - } elseif ($includeEmptyValues || $val) { - $arr0[$key] = $val; - } + } elseif ( + (!$notAddKeys || isset($arr0[$key])) && + ($includeEmptyValues || $val) + ) { + $arr0[$key] = $val; } } reset($arr0); diff --git a/typo3/sysext/core/Tests/Unit/Utility/GeneralUtilityTest.php b/typo3/sysext/core/Tests/Unit/Utility/GeneralUtilityTest.php index f00ac6e2be35..5c6e9ece3e6c 100644 --- a/typo3/sysext/core/Tests/Unit/Utility/GeneralUtilityTest.php +++ b/typo3/sysext/core/Tests/Unit/Utility/GeneralUtilityTest.php @@ -4020,14 +4020,16 @@ class GeneralUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase { 'first' => array( 'second' => 'second', 'third' => 'third' - ) + ), + 'fifth' => array() ); $array2 = array( 'first' => array( 'second' => 'overrule', 'third' => '__UNSET', 'fourth' => 'overrile' - ) + ), + 'fifth' => '__UNSET' ); $expected = array( 'first' => array(