diff --git a/typo3/sysext/core/Classes/Utility/ArrayUtility.php b/typo3/sysext/core/Classes/Utility/ArrayUtility.php index 3273d9a76e9586d12ba18a00dc695c7dab1097e2..be2542231f2c9c3dc82bbe87ab5471f322aefefa 100644 --- a/typo3/sysext/core/Classes/Utility/ArrayUtility.php +++ b/typo3/sysext/core/Classes/Utility/ArrayUtility.php @@ -674,7 +674,10 @@ class ArrayUtility $differenceArray[$key] = $value; } elseif (is_array($value)) { if (is_array($array2[$key])) { - $differenceArray[$key] = self::arrayDiffAssocRecursive($value, $array2[$key]); + $recursiveResult = self::arrayDiffAssocRecursive($value, $array2[$key]); + if (!empty($recursiveResult)) { + $differenceArray[$key] = $recursiveResult; + } } } } diff --git a/typo3/sysext/core/Tests/Unit/Utility/ArrayUtilityTest.php b/typo3/sysext/core/Tests/Unit/Utility/ArrayUtilityTest.php index fc6528e7bf8b99f47fed7cacdbb54ccb84af4ade..af1ef6052e7e63d670e623218264d05c3cdc1433 100644 --- a/typo3/sysext/core/Tests/Unit/Utility/ArrayUtilityTest.php +++ b/typo3/sysext/core/Tests/Unit/Utility/ArrayUtilityTest.php @@ -2085,7 +2085,7 @@ class ArrayUtilityTest extends UnitTestCase ] ]; $array2 = [ - 'key1' => 'value1', + 'key1' => 'valueDoesNotMatter', 'key2' => [ 'key21' => 'value21', 'key23' => [ @@ -2121,7 +2121,7 @@ class ArrayUtilityTest extends UnitTestCase $array2 = [ 'key1' => 'value1', 'key2' => [ - 'key21' => 'value21' + 'key21' => 'valueDoesNotMatter' ] ]; $expectedResult = [ @@ -2131,6 +2131,32 @@ class ArrayUtilityTest extends UnitTestCase $this->assertEquals($expectedResult, $actualResult); } + /** + * @test + */ + public function arrayDiffAssocRecursiveReturnsEmptyIfEqual() + { + $array1 = [ + 'key1' => [ + 'key11' => 'value11', + 'key12' => 'value12' + ], + 'key2' => 'value2', + 'key3' => 'value3' + ]; + $array2 = [ + 'key1' => [ + 'key11' => 'valueDoesNotMatter', + 'key12' => 'value12' + ], + 'key2' => 'value2', + 'key3' => 'value3' + ]; + $expectedResult = []; + $actualResult = ArrayUtility::arrayDiffAssocRecursive($array1, $array2); + $this->assertEquals($expectedResult, $actualResult); + } + ////////////////////////////////////// // Tests concerning naturalKeySortRecursive //////////////////////////////////////