From 34e392709e3e0c4f17f98400087c304aff9ba344 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20K=C3=A4hm?= Date: Thu, 7 Mar 2024 02:34:29 +0100 Subject: [PATCH] [BUGFIX] follow-up: false as field value is not allowed This change is a follow-up of #3901, which was introduced to allow following values in Apache Solr fields: * numeric 0 * boolean false which lead to countless-unwanted numeric fields with 0 value in Apache Solr documents. The background: TypoScript can return the strings only, and all empty values lead to numeric 0. This change tries to avoid mispelled casting of numbers and lets the `AbstractIndexer::ensureFieldValueType()` return PHPs `null` if the value isn't a number. Relates: #3900, #3901 --- Classes/IndexQueue/AbstractIndexer.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Classes/IndexQueue/AbstractIndexer.php b/Classes/IndexQueue/AbstractIndexer.php index 3dc4f6e4a2..379054a13f 100644 --- a/Classes/IndexQueue/AbstractIndexer.php +++ b/Classes/IndexQueue/AbstractIndexer.php @@ -24,6 +24,7 @@ use TYPO3\CMS\Core\Core\Environment; use TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser; use TYPO3\CMS\Core\Utility\GeneralUtility; +use TYPO3\CMS\Core\Utility\MathUtility; use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController; use UnexpectedValueException; @@ -282,12 +283,12 @@ protected function ensureFieldValueType(mixed $value, string $fieldType): mixed switch ($fieldType) { case 'int': case 'tInt': - $value = (int)$value; + $value = MathUtility::canBeInterpretedAsInteger($value) ? (int)$value : null; break; case 'float': case 'tFloat': - $value = (float)$value; + $value = MathUtility::canBeInterpretedAsInteger($value) || MathUtility::canBeInterpretedAsFloat($value) ? (float)$value : null; break; case 'long': // long and double do not exist in PHP @@ -297,7 +298,7 @@ protected function ensureFieldValueType(mixed $value, string $fieldType): mixed // remove anything that's not a number or negative/minus sign $value = preg_replace('/[^0-9\\-]/', '', $value); if (trim($value) === '') { - $value = 0; + $value = null; } break; case 'double': @@ -305,7 +306,7 @@ protected function ensureFieldValueType(mixed $value, string $fieldType): mixed case 'tDouble4': // as long as it's numeric we'll take it, int or float doesn't matter if (!is_numeric($value)) { - $value = 0; + $value = null; } break;