Skip to content

Commit

Permalink
Merge pull request #27 from kdambekalns/bugfix/26-select-numeric-options
Browse files Browse the repository at this point in the history
BUGFIX: Loosely compare values in isOptionSelected
  • Loading branch information
mhsdesign authored Dec 24, 2022
2 parents fdc9f90 + 41c5c36 commit 98ddc8d
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions Classes/Fusion/SelectOptionsImplementation.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,19 @@ public function translate(FormElementInterface $element, string $translationId,

private function isOptionSelected($optionValue): bool
{
// this method compares values "type unsafe" because due to the
// nature of web requests numbers and strings cannot really be
// distinguished. This leads to false negatives if option values
// are given as numbers but incoming data is a string.
$elementValue = ($this->runtime->getCurrentContext())['elementValue'] ?? null;
if ($optionValue === $elementValue) {
/** @noinspection TypeUnsafeComparisonInspection */
if ($optionValue == $elementValue) {
return true;
}
/** @noinspection TypeUnsafeArraySearchInspection */
if (is_array($elementValue) && in_array($optionValue, $elementValue)) {
return true;
}
return false;
}
}
}

0 comments on commit 98ddc8d

Please sign in to comment.