Skip to content

Commit

Permalink
[BUGFIX] follow-up: false as field value is not allowed
Browse files Browse the repository at this point in the history
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
  • Loading branch information
dkd-kaehm authored and dkd-friedrich committed Mar 7, 2024
1 parent 6d16a09 commit 34e3927
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions Classes/IndexQueue/AbstractIndexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand All @@ -297,15 +298,15 @@ 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':
case 'tDouble':
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;

Expand Down

0 comments on commit 34e3927

Please sign in to comment.