Skip to content

Commit

Permalink
[BUGFIX] Ensure integer comparison for check of haystack containing d…
Browse files Browse the repository at this point in the history
…omain object

Close: #1909
  • Loading branch information
NamelessCoder committed Jul 18, 2024
1 parent 8953954 commit e0e7dd8
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions Classes/ViewHelpers/Condition/Iterator/ContainsViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,18 +118,19 @@ protected static function assertHaystackIsQueryResultAndHasNeedle($haystack, $ne

/**
* @param array|DomainObjectInterface[]|QueryResult|ObjectStorage $haystack
* @param integer|DomainObjectInterface $needle
* @param string|int|DomainObjectInterface $needle
* @return boolean|integer
*/
protected static function assertHaystackIsObjectStorageAndHasNeedle($haystack, $needle)
{
$index = 0;
if ($needle instanceof AbstractDomainObject) {
$needle = $needle->getUid();
if ($needle instanceof DomainObjectInterface) {
$needle = (integer) $needle->getUid();
}

/** @var DomainObjectInterface $candidate */
foreach ($haystack as $candidate) {
if ($candidate->getUid() === $needle) {
if ($candidate->getUid() === (integer) $needle) {
return $index;
}
$index++;
Expand All @@ -155,7 +156,7 @@ protected static function assertHaystackIsArrayAndHasNeedle($haystack, $needle,
return $result;
} else {
foreach ($haystack as $index => $straw) {
if ((integer) $straw->getUid() === $needle->getUid()) {
if ((integer) $straw->getUid() === (integer) $needle->getUid()) {
return $index;
}
}
Expand Down

0 comments on commit e0e7dd8

Please sign in to comment.