From cf970ccd66539eeb519aedde5699cbc079d18e9b 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/+/75179 Reviewed-by: Oliver Klee <typo3-coding@oliverklee.de> Reviewed-by: Benni Mack <benni@typo3.org> Reviewed-by: Oliver Bartsch <bo@cedev.de> Tested-by: core-ci <typo3@b13.com> Tested-by: Benni Mack <benni@typo3.org> Tested-by: Nikita Hovratov <nikita.h@live.de> Tested-by: Oliver Bartsch <bo@cedev.de> --- .../core/Classes/Utility/GeneralUtility.php | 5 ++++- .../Tests/Unit/Utility/GeneralUtilityTest.php | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/typo3/sysext/core/Classes/Utility/GeneralUtility.php b/typo3/sysext/core/Classes/Utility/GeneralUtility.php index 44693074a183..829608eda8ed 100644 --- a/typo3/sysext/core/Classes/Utility/GeneralUtility.php +++ b/typo3/sysext/core/Classes/Utility/GeneralUtility.php @@ -2127,7 +2127,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; diff --git a/typo3/sysext/core/Tests/Unit/Utility/GeneralUtilityTest.php b/typo3/sysext/core/Tests/Unit/Utility/GeneralUtilityTest.php index da392a374d4e..14fc4accfa7b 100644 --- a/typo3/sysext/core/Tests/Unit/Utility/GeneralUtilityTest.php +++ b/typo3/sysext/core/Tests/Unit/Utility/GeneralUtilityTest.php @@ -4107,4 +4107,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::assertMatchesRegularExpression('/^.*\/tests\/' . $uniqueFilename . '\.[0-9]+\.css/', $versionedFilename); + } } -- GitLab