From a7bc75b469921c1557a35ddfbf822e9428d7afe1 Mon Sep 17 00:00:00 2001 From: Thomas Hohn <thomas@hohn.dk> Date: Fri, 27 Jan 2023 10:57:43 +0100 Subject: [PATCH] [BUGFIX] Fix PHP 8 warning in RootlineUtility Sanitize the mountPointParameter in class constructor. Resolves: #99731 Releases: main, 11.5 Change-Id: Ic6fec228c462c7ec4a75a7efc934d7d17fc5c1e0 Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/77657 Tested-by: core-ci <typo3@b13.com> Tested-by: Christian Kuhn <lolli@schwarzbu.ch> Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch> --- .../core/Classes/Utility/RootlineUtility.php | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/typo3/sysext/core/Classes/Utility/RootlineUtility.php b/typo3/sysext/core/Classes/Utility/RootlineUtility.php index 13e661495de4..f4867a4273d6 100644 --- a/typo3/sysext/core/Classes/Utility/RootlineUtility.php +++ b/typo3/sysext/core/Classes/Utility/RootlineUtility.php @@ -133,7 +133,7 @@ class RootlineUtility */ public function __construct($uid, $mountPointParameter = '', $context = null) { - $this->mountPointParameter = trim((string)$mountPointParameter); + $this->mountPointParameter = $this->sanitizeMountPointParameter($mountPointParameter); if (!($context instanceof Context)) { $context = GeneralUtility::makeInstance(Context::class); } @@ -419,6 +419,23 @@ class RootlineUtility return $mountedPageData; } + /** + * Sanitize the MountPoint Parameter + * Splits the MP-Param via "," and removes mountpoints + * that don't have the format \d+-\d+ + */ + protected function sanitizeMountPointParameter(string $mountPointParameter): string + { + $mountPoints = GeneralUtility::trimExplode(',', $mountPointParameter); + foreach ($mountPoints as $key => $mP) { + // If MP has incorrect format, discard it + if (!preg_match('/^\d+-\d+$/', $mP)) { + unset($mountPoints[$key]); + } + } + return implode(',', $mountPoints); + } + /** * Parse the MountPoint Parameters * Splits the MP-Param via "," for several nested mountpoints -- GitLab