From 177b087f8687bb7dff2038d0e4e703174ad93d43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20B=C3=BCrk?= Date: Tue, 26 Oct 2021 19:52:35 +0200 Subject: [PATCH] [BUGFIX] Avoid calling trim(null) in PageRenderer PageRender sanitizes array values in two methods, using array walk with trim(). These values can be other types then string, which trigger deprecation warning in PHP 8.1. This patch change the array walk to an closure to have an explicit type cast to string for passing the value to trim(). Additional a return type ': string' is added to the protected method getTemplate(), as this method always returns a string. Resolves: #95788 Releases: master Change-Id: Id0cdef928f977fdc1a9d476475bd3a44c5783922 Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/71984 Tested-by: core-ci Tested-by: Jochen Tested-by: Christian Kuhn Reviewed-by: Jochen Reviewed-by: Christian Kuhn --- typo3/sysext/core/Classes/Page/PageRenderer.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/typo3/sysext/core/Classes/Page/PageRenderer.php b/typo3/sysext/core/Classes/Page/PageRenderer.php index e4aac7b3114b..af492b849989 100644 --- a/typo3/sysext/core/Classes/Page/PageRenderer.php +++ b/typo3/sysext/core/Classes/Page/PageRenderer.php @@ -1924,7 +1924,7 @@ protected function getPreparedMarkerArray($jsLibs, $jsFiles, $jsFooterFiles, $cs 'JS_INLINE_FOOTER' => $jsFooterInline, 'BODY' => $this->bodyContent, ]; - $markerArray = array_map('trim', $markerArray); + $markerArray = array_map(static fn ($item) => (trim((string)$item)), $markerArray); return $markerArray; } @@ -1959,7 +1959,7 @@ protected function getPreparedMarkerArrayForPageWithUncachedObjects($substituteH 'JS_INCLUDE_FOOTER' => '', 'JS_INLINE_FOOTER' => '', ]; - $markerArray = array_map('trim', $markerArray); + $markerArray = array_map(static fn ($item) => (trim((string)$item)), $markerArray); return $markerArray; } @@ -1968,7 +1968,7 @@ protected function getPreparedMarkerArrayForPageWithUncachedObjects($substituteH * * @return string */ - protected function getTemplate() + protected function getTemplate(): string { $templateFile = GeneralUtility::getFileAbsFileName($this->templateFile); if (is_file($templateFile)) {