From 23e8c8bc8587bb39d8c4a9900ee049dc36bafad0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chris=20M=C3=BCller?= <typo3@krue.ml> Date: Wed, 17 Aug 2022 20:35:49 +0200 Subject: [PATCH] [BUGFIX] Avoid undefined array keys error using stdWrap_bytes If either labels or base are not given, the default values kick in: labels = iec and base = 1024 With the new fallback values in place test ContentObjectRendererTest notAllStdWrapProcessorsAreCallableWithEmptyConfiguration() needs a minor adaption. Resolves: #98154 Releases: main, 11.5 Change-Id: Ib2a242454197be94a75fb3d5bffbb8d0be8a1523 Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/75484 Tested-by: Andreas Fernandez <a.fernandez@scripting-base.de> Tested-by: core-ci <typo3@b13.com> Tested-by: Christian Kuhn <lolli@schwarzbu.ch> Reviewed-by: Andreas Fernandez <a.fernandez@scripting-base.de> Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch> --- .../ContentObject/ContentObjectRenderer.php | 2 +- .../ContentObject/ContentObjectRendererTest.php | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php b/typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php index c39451673706..54824de3cb5a 100644 --- a/typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php +++ b/typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php @@ -1960,7 +1960,7 @@ class ContentObjectRenderer implements LoggerAwareInterface */ public function stdWrap_bytes($content = '', $conf = []) { - return GeneralUtility::formatSize((int)$content, $conf['bytes.']['labels'], $conf['bytes.']['base']); + return GeneralUtility::formatSize((int)$content, $conf['bytes.']['labels'] ?? '', $conf['bytes.']['base'] ?? 0); } /** diff --git a/typo3/sysext/frontend/Tests/Unit/ContentObject/ContentObjectRendererTest.php b/typo3/sysext/frontend/Tests/Unit/ContentObject/ContentObjectRendererTest.php index 52cdf14b94a2..2d01fd4ef92d 100644 --- a/typo3/sysext/frontend/Tests/Unit/ContentObject/ContentObjectRendererTest.php +++ b/typo3/sysext/frontend/Tests/Unit/ContentObject/ContentObjectRendererTest.php @@ -3838,12 +3838,12 @@ class ContentObjectRendererTest extends UnitTestCase * - Almost all stdWrap_[type] are callable if called with 2 parameters: * - string $content Empty string. * - array $conf ['type' => '', 'type.' => []]. - * - Exceptions: stdWrap_numRows, stdWrap_split + * - Exceptions: stdWrap_numRows * - The overall count is 91. * * Note: * - * The two exceptions break, if the configuration is empty. This test just + * The exceptions break, if the configuration is empty. This test just * tracks the different behaviour to gain information. It doesn't mean * that it is an issue. * @@ -3857,7 +3857,7 @@ class ContentObjectRendererTest extends UnitTestCase $linkFactory->create(Argument::cetera())->willReturn(new LinkResult('', '')); GeneralUtility::addInstance(LinkFactory::class, $linkFactory->reveal()); - $expectExceptions = ['numRows', 'bytes']; + $expectExceptions = ['numRows']; $count = 0; $processors = []; $exceptions = []; @@ -4276,6 +4276,16 @@ class ContentObjectRendererTest extends UnitTestCase '1234567890', ['labels' => '', 'base' => 0], ], + 'value 1234 iec no base' => [ + '1.21 Ki', + '1234', + ['labels' => 'iec'], + ], + 'value 1234 no labels base set' => [ + '1.21 Ki', + '1234', + ['base' => 0], + ], ]; } -- GitLab