Skip to content

Commit 98ddc8d

Browse files
authored
Merge pull request #27 from kdambekalns/bugfix/26-select-numeric-options
BUGFIX: Loosely compare values in isOptionSelected
2 parents fdc9f90 + 41c5c36 commit 98ddc8d

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

Classes/Fusion/SelectOptionsImplementation.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,19 @@ public function translate(FormElementInterface $element, string $translationId,
6868

6969
private function isOptionSelected($optionValue): bool
7070
{
71+
// this method compares values "type unsafe" because due to the
72+
// nature of web requests numbers and strings cannot really be
73+
// distinguished. This leads to false negatives if option values
74+
// are given as numbers but incoming data is a string.
7175
$elementValue = ($this->runtime->getCurrentContext())['elementValue'] ?? null;
72-
if ($optionValue === $elementValue) {
76+
/** @noinspection TypeUnsafeComparisonInspection */
77+
if ($optionValue == $elementValue) {
7378
return true;
7479
}
80+
/** @noinspection TypeUnsafeArraySearchInspection */
7581
if (is_array($elementValue) && in_array($optionValue, $elementValue)) {
7682
return true;
7783
}
7884
return false;
7985
}
80-
}
86+
}

0 commit comments

Comments
 (0)