Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix comparing arrays with entity references #1237

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/helpers/DataHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,19 @@ public static function arrayCompare($array1, $array2): bool|array
*/
private static function _compareSimpleValues($fields, $key, $firstValue, $secondValue): bool
{
// When the values are arrays filled with numbers then they most likely represent references to elements.
// Unfortunately these arrays sometimes have non-matching keys, while the values are the same, i.e. reference
// the same elements. In this case, we should determine that the values are the same.
if (Hash::check($fields, $key)
&& is_array($firstValue)
&& is_array($secondValue)
&& array_reduce($firstValue, static fn($carry, $item) => $carry && is_numeric($item), true)
&& array_reduce($secondValue, static fn($carry, $item) => $carry && is_numeric($item), true)
&& array_values($firstValue) == array_values($secondValue)
) {
return true;
}

/** @noinspection TypeUnsafeComparisonInspection */
// Should probably do a strict check, but doing this for backwards compatibility.
if (Hash::check($fields, $key) && ($firstValue == $secondValue)) {
Expand Down