[BUGFIX] array_merge_recursive_overrule: __UNSET for array values 29/17529/4
authorSebastian Michaelsen <michaelsen@t3seo.de>
Tue, 11 Dec 2012 10:43:57 +0000 (11:43 +0100)
committerTobias Liebig <tobias.liebig@typo3.org>
Thu, 17 Jan 2013 07:25:41 +0000 (08:25 +0100)
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/17529
Reviewed-by: Markus Klein
Reviewed-by: Sebastian Michaelsen
Tested-by: Sebastian Michaelsen
Reviewed-by: Tobias Liebig
Tested-by: Tobias Liebig
typo3/sysext/core/Classes/Utility/GeneralUtility.php
typo3/sysext/core/Tests/Unit/Utility/GeneralUtilityTest.php

index d610299..abeb964 100644 (file)
@@ -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);
index f00ac6e..5c6e9ec 100644 (file)
@@ -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(