Skip to content

Commit

Permalink
[BUGFIX] Correctly handle identical arrays in arrayDiffAssocRecursive
Browse files Browse the repository at this point in the history
Add a new test to make sure that identical input arrays also deliver
an empty result as difference.

Resolves: #84067
Releases: master, 8.7, 7.6
Change-Id: Ia16ca9560094c4ae42eb69cac9e09cd4bef7dc4e
Reviewed-on: https://review.typo3.org/55923
Reviewed-by: Johannes Kasberger <johannes.kasberger@reelworx.at>
Tested-by: Johannes Kasberger <johannes.kasberger@reelworx.at>
Reviewed-by: Mathias Brodala <mbrodala@pagemachine.de>
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
  • Loading branch information
liayn authored and georgringer committed Feb 27, 2018
1 parent 9a5643f commit 17fcf20
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
5 changes: 4 additions & 1 deletion typo3/sysext/core/Classes/Utility/ArrayUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,10 @@ public static function arrayDiffAssocRecursive(array $array1, array $array2)
$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;
}
}
}
}
Expand Down
30 changes: 28 additions & 2 deletions typo3/sysext/core/Tests/Unit/Utility/ArrayUtilityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2102,7 +2102,7 @@ public function arrayDiffAssocRecursiveHandlesMultiDimensionalArrays()
]
];
$array2 = [
'key1' => 'value1',
'key1' => 'valueDoesNotMatter',
'key2' => [
'key21' => 'value21',
'key23' => [
Expand Down Expand Up @@ -2138,7 +2138,7 @@ public function arrayDiffAssocRecursiveHandlesMixedArrays()
$array2 = [
'key1' => 'value1',
'key2' => [
'key21' => 'value21'
'key21' => 'valueDoesNotMatter'
]
];
$expectedResult = [
Expand All @@ -2148,6 +2148,32 @@ public function arrayDiffAssocRecursiveHandlesMixedArrays()
$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
//////////////////////////////////////
Expand Down

0 comments on commit 17fcf20

Please sign in to comment.