From 7fa71a1d224fed69017f1dfeac3c79610d03a3af Mon Sep 17 00:00:00 2001 From: Nikita Hovratov <nikita.h@live.de> Date: Tue, 5 Oct 2021 22:17:49 +0200 Subject: [PATCH] [BUGFIX] Add parenthesis where operation result is enforced The coalesce operator has a relatively low precedence over other operators. If used as part of other expressions, it is almost always necessary to wrap it in parenthesis. Otherwise unexpected behaviour or undefined array key errors (in PHP 8.0) may occur. Resolves: #95482 Releases: master, 10.4 Change-Id: I4ddecdbeab03c215477f77742674ded01bc29257 Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/71449 Tested-by: core-ci <typo3@b13.com> Tested-by: Benjamin Franzke <bfr@qbus.de> Tested-by: Oliver Bartsch <bo@cedev.de> Reviewed-by: Benjamin Franzke <bfr@qbus.de> Reviewed-by: Oliver Bartsch <bo@cedev.de> --- .../Classes/Controller/SiteConfigurationController.php | 2 +- .../Classes/Persistence/Generic/Storage/Typo3DbBackend.php | 2 +- .../Classes/ContentObject/Menu/AbstractMenuContentObject.php | 2 +- typo3/sysext/frontend/Classes/Http/RequestHandler.php | 4 ++-- typo3/sysext/impexp/Classes/Export.php | 2 +- .../install/Classes/Updates/BackendUserLanguageMigration.php | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/typo3/sysext/backend/Classes/Controller/SiteConfigurationController.php b/typo3/sysext/backend/Classes/Controller/SiteConfigurationController.php index ef50c88550a0..ae748bbcec7c 100644 --- a/typo3/sysext/backend/Classes/Controller/SiteConfigurationController.php +++ b/typo3/sysext/backend/Classes/Controller/SiteConfigurationController.php @@ -270,7 +270,7 @@ class SiteConfigurationController $currentSiteConfiguration = []; $isNewConfiguration = true; $pageId = (int)$parsedBody['rootPageId']; - if (!$pageId > 0) { + if ($pageId <= 0) { // Early validation of rootPageId - it must always be given and greater than 0 throw new \RuntimeException('No root page id found', 1521719709); } diff --git a/typo3/sysext/extbase/Classes/Persistence/Generic/Storage/Typo3DbBackend.php b/typo3/sysext/extbase/Classes/Persistence/Generic/Storage/Typo3DbBackend.php index 2ece5fc370b4..e9970c8d287b 100644 --- a/typo3/sysext/extbase/Classes/Persistence/Generic/Storage/Typo3DbBackend.php +++ b/typo3/sysext/extbase/Classes/Persistence/Generic/Storage/Typo3DbBackend.php @@ -501,7 +501,7 @@ class Typo3DbBackend implements BackendInterface, SingletonInterface $querySettings = $query->getQuerySettings(); // If current row is a translation select its parent $languageOfCurrentRecord = 0; - if ($GLOBALS['TCA'][$tableName]['ctrl']['languageField'] ?? null + if (($GLOBALS['TCA'][$tableName]['ctrl']['languageField'] ?? null) && $row[$GLOBALS['TCA'][$tableName]['ctrl']['languageField']] ?? 0 ) { $languageOfCurrentRecord = $row[$GLOBALS['TCA'][$tableName]['ctrl']['languageField']]; diff --git a/typo3/sysext/frontend/Classes/ContentObject/Menu/AbstractMenuContentObject.php b/typo3/sysext/frontend/Classes/ContentObject/Menu/AbstractMenuContentObject.php index be68f7a15e07..ec85e3287fb8 100644 --- a/typo3/sysext/frontend/Classes/ContentObject/Menu/AbstractMenuContentObject.php +++ b/typo3/sysext/frontend/Classes/ContentObject/Menu/AbstractMenuContentObject.php @@ -1423,7 +1423,7 @@ abstract class AbstractMenuContentObject protected function changeLinksForAccessRestrictedPages(&$LD, $page, $mainTarget, $typeOverride) { // If access restricted pages should be shown in menus, change the link of such pages to link to a redirection page: - if ($this->mconf['showAccessRestrictedPages'] ?? false && $this->mconf['showAccessRestrictedPages'] !== 'NONE' && !$this->getTypoScriptFrontendController()->checkPageGroupAccess($page)) { + if (($this->mconf['showAccessRestrictedPages'] ?? false) && $this->mconf['showAccessRestrictedPages'] !== 'NONE' && !$this->getTypoScriptFrontendController()->checkPageGroupAccess($page)) { $thePage = $this->sys_page->getPage($this->mconf['showAccessRestrictedPages']); $addParams = str_replace( [ diff --git a/typo3/sysext/frontend/Classes/Http/RequestHandler.php b/typo3/sysext/frontend/Classes/Http/RequestHandler.php index aae9f01a79fd..e75077c6add9 100644 --- a/typo3/sysext/frontend/Classes/Http/RequestHandler.php +++ b/typo3/sysext/frontend/Classes/Http/RequestHandler.php @@ -405,11 +405,11 @@ class RequestHandler implements RequestHandlerInterface $stylesFromPlugins = ''; foreach ($controller->tmpl->setup['plugin.'] as $key => $iCSScode) { if (is_array($iCSScode)) { - if ($iCSScode['_CSS_DEFAULT_STYLE'] ?? false && empty($controller->config['config']['removeDefaultCss'])) { + if (($iCSScode['_CSS_DEFAULT_STYLE'] ?? false) && empty($controller->config['config']['removeDefaultCss'])) { $cssDefaultStyle = $controller->cObj->stdWrapValue('_CSS_DEFAULT_STYLE', $iCSScode ?? []); $stylesFromPlugins .= '/* default styles for extension "' . substr($key, 0, -1) . '" */' . LF . $cssDefaultStyle . LF; } - if ($iCSScode['_CSS_PAGE_STYLE'] ?? false && empty($controller->config['config']['removePageCss'])) { + if (($iCSScode['_CSS_PAGE_STYLE'] ?? false) && empty($controller->config['config']['removePageCss'])) { $cssPageStyle = implode(LF, $iCSScode['_CSS_PAGE_STYLE']); if (isset($iCSScode['_CSS_PAGE_STYLE.'])) { $cssPageStyle = $controller->cObj->stdWrap($cssPageStyle, $iCSScode['_CSS_PAGE_STYLE.']); diff --git a/typo3/sysext/impexp/Classes/Export.php b/typo3/sysext/impexp/Classes/Export.php index 09b7af156ca9..775204a14754 100644 --- a/typo3/sysext/impexp/Classes/Export.php +++ b/typo3/sysext/impexp/Classes/Export.php @@ -347,7 +347,7 @@ class Export extends ImportExport protected function removeExcludedPagesFromPageTree(array &$pageTree): void { foreach ($pageTree as $pid => $value) { - if ($this->isRecordExcluded('pages', (int)$pageTree[$pid]['uid'] ?? 0)) { + if ($this->isRecordExcluded('pages', (int)($pageTree[$pid]['uid'] ?? 0))) { unset($pageTree[$pid]); } elseif (is_array($pageTree[$pid]['subrow'] ?? null)) { $this->removeExcludedPagesFromPageTree($pageTree[$pid]['subrow']); diff --git a/typo3/sysext/install/Classes/Updates/BackendUserLanguageMigration.php b/typo3/sysext/install/Classes/Updates/BackendUserLanguageMigration.php index 356d34f459b7..e3bd3e62249a 100644 --- a/typo3/sysext/install/Classes/Updates/BackendUserLanguageMigration.php +++ b/typo3/sysext/install/Classes/Updates/BackendUserLanguageMigration.php @@ -60,7 +60,7 @@ class BackendUserLanguageMigration implements UpgradeWizardInterface $connection = $this->getConnectionPool()->getConnectionForTable(self::TABLE_NAME); foreach ($this->getRecordsToUpdate() as $record) { - $currentDatabaseFieldValue = (string)$record['lang'] ?? ''; + $currentDatabaseFieldValue = (string)($record['lang'] ?? ''); $uc = unserialize($user['uc'] ?? '', ['allowed_classes' => false]); // Check if the user has a preference set, otherwise use the default from the database field // however, "default" is now explicitly set. -- GitLab