From c102739e0ff0b1e0f661c4b72b9f11549b3dbbc3 Mon Sep 17 00:00:00 2001 From: Oliver Bartsch <bo@cedev.de> Date: Thu, 14 Jul 2022 14:56:10 +0200 Subject: [PATCH] [BUGFIX] Skip resolving backpath for already absolute paths In case GU::createVersionNumberedFilename() receives a file with an absolute path, no back path should be resolved since the resolved path will always be invalid, which led to no version number got added to the filename anymore. This is now fixed by checking for the path being absolute. Resolves: #97939 Releases: main, 11.5, 10.4 Change-Id: I5bb0150fa27b8c9c1af2aa99bd8baacd55889245 Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/75142 Tested-by: core-ci <typo3@b13.com> Tested-by: Oliver Bartsch <bo@cedev.de> Reviewed-by: Oliver Bartsch <bo@cedev.de> --- .../core/Classes/Utility/GeneralUtility.php | 7 +++++-- .../Tests/Unit/Utility/GeneralUtilityTest.php | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/typo3/sysext/core/Classes/Utility/GeneralUtility.php b/typo3/sysext/core/Classes/Utility/GeneralUtility.php index 83e7b7828891..3b1264f1dcf5 100644 --- a/typo3/sysext/core/Classes/Utility/GeneralUtility.php +++ b/typo3/sysext/core/Classes/Utility/GeneralUtility.php @@ -2437,7 +2437,10 @@ class GeneralUtility public static function createVersionNumberedFilename($file) { $lookupFile = explode('?', $file); - $path = self::resolveBackPath(self::dirname(Environment::getCurrentScript()) . '/' . $lookupFile[0]); + $path = $lookupFile[0]; + if (!PathUtility::isAbsolutePath($path)) { + $path = self::resolveBackPath(self::dirname(Environment::getCurrentScript()) . '/' . $path); + } $doNothing = false; if (TYPO3_MODE === 'FE') { @@ -2474,7 +2477,7 @@ class GeneralUtility array_push($name, filemtime($path), $extension); $fullName = implode('.', $name); // Append potential query string - $fullName .= $lookupFile[1] ? '?' . $lookupFile[1] : ''; + $fullName .= !empty($lookupFile[1]) ? '?' . $lookupFile[1] : ''; } } return $fullName; diff --git a/typo3/sysext/core/Tests/Unit/Utility/GeneralUtilityTest.php b/typo3/sysext/core/Tests/Unit/Utility/GeneralUtilityTest.php index 8e6da0dbaf90..67f7a5d24f53 100644 --- a/typo3/sysext/core/Tests/Unit/Utility/GeneralUtilityTest.php +++ b/typo3/sysext/core/Tests/Unit/Utility/GeneralUtilityTest.php @@ -4606,4 +4606,23 @@ class GeneralUtilityTest extends UnitTestCase $result = GeneralUtility::locationHeaderUrl($path); self::assertSame($expected, $result); } + + /** + * @test + */ + public function createVersionNumberedFilenameDoesNotResolveBackpathForAbsolutePath(): void + { + $GLOBALS['TYPO3_CONF_VARS']['BE']['versionNumberInFilename'] = true; + + $uniqueFilename = StringUtility::getUniqueId() . 'backend'; + $testFileDirectory = Environment::getVarPath() . '/tests/'; + $testFilepath = $testFileDirectory . $uniqueFilename . '.css'; + $this->testFilesToDelete[] = $testFilepath; + GeneralUtility::mkdir_deep($testFileDirectory); + touch($testFilepath); + + $versionedFilename = GeneralUtility::createVersionNumberedFilename($testFilepath); + + self::assertRegExp('/^.*\/tests\/' . $uniqueFilename . '\.[0-9]+\.css/', $versionedFilename); + } } -- GitLab