From bef898095ef3de69146a94910342403332f6d9eb Mon Sep 17 00:00:00 2001 From: Helmut Hummel <helmut.hummel@typo3.org> Date: Wed, 30 Sep 2015 20:27:35 +0200 Subject: [PATCH] [BUGFIX] Remove trailing slash from autoload information files If an extension defines a classmap in ext_emconf.php or composer.json which points to a file instead of a directory. The relative path calculation adds a trailing slash to the file name, which breaks the class loading. This trailing slash needs to be removed. As a bonus the obsolete trailing slash is also removed from directories. Resolves: #70234 Releases: master Change-Id: Id54c2692e10b8ec3283a4e3447c289dc4319042c Reviewed-on: http://review.typo3.org/43669 Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch> Tested-by: Christian Kuhn <lolli@schwarzbu.ch> Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl> Tested-by: Wouter Wolters <typo3@wouterwolters.nl> Reviewed-by: Daniel Goerz <ervaude@gmail.com> Tested-by: Daniel Goerz <ervaude@gmail.com> Reviewed-by: Georg Ringer <georg.ringer@gmail.com> Tested-by: Georg Ringer <georg.ringer@gmail.com> --- .../core/Classes/Core/ClassLoadingInformationGenerator.php | 6 +++++- .../Unit/Core/ClassLoadingInformationGeneratorTest.php | 2 +- .../Tests/Unit/Core/Fixtures/test_extension/composer.json | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/typo3/sysext/core/Classes/Core/ClassLoadingInformationGenerator.php b/typo3/sysext/core/Classes/Core/ClassLoadingInformationGenerator.php index 05e5116b743e..7c4a9a7f09fc 100644 --- a/typo3/sysext/core/Classes/Core/ClassLoadingInformationGenerator.php +++ b/typo3/sysext/core/Classes/Core/ClassLoadingInformationGenerator.php @@ -235,7 +235,11 @@ EOF; $packageRealPath = GeneralUtility::fixWindowsFilePath(realpath($packagePath)); $relativePackagePath = rtrim(substr($packagePath, strlen($this->installationRoot)), '/'); if ($relativeToRoot) { - $relativePathToClassFile = $relativePackagePath . '/' . ltrim(substr($realPathOfClassFile, strlen($packageRealPath)), '/'); + if ($realPathOfClassFile === $packageRealPath) { + $relativePathToClassFile = $relativePackagePath; + } else { + $relativePathToClassFile = $relativePackagePath . '/' . ltrim(substr($realPathOfClassFile, strlen($packageRealPath)), '/'); + } } else { $relativePathToClassFile = ltrim(substr($realPathOfClassFile, strlen($packageRealPath)), '/'); } diff --git a/typo3/sysext/core/Tests/Unit/Core/ClassLoadingInformationGeneratorTest.php b/typo3/sysext/core/Tests/Unit/Core/ClassLoadingInformationGeneratorTest.php index 7015471c4eee..591f6220e0bd 100644 --- a/typo3/sysext/core/Tests/Unit/Core/ClassLoadingInformationGeneratorTest.php +++ b/typo3/sysext/core/Tests/Unit/Core/ClassLoadingInformationGeneratorTest.php @@ -71,7 +71,7 @@ class ClassLoadingInformationGeneratorTest extends UnitTestCase { $this->assertArrayHasKey('psr-4File', $files); $this->assertArrayHasKey('classMapFile', $files); - $this->assertContains('\'TYPO3\\\\CMS\\\\TestExtension\\\\\' => array($typo3InstallDir . \'/Fixtures/test_extension/Classes/\')', $files['psr-4File']); + $this->assertContains('\'TYPO3\\\\CMS\\\\TestExtension\\\\\' => array($typo3InstallDir . \'/Fixtures/test_extension/Classes\')', $files['psr-4File']); $this->assertContains('$typo3InstallDir . \'/Fixtures/test_extension/Resources/PHP/Test.php\'', $files['classMapFile']); } diff --git a/typo3/sysext/core/Tests/Unit/Core/Fixtures/test_extension/composer.json b/typo3/sysext/core/Tests/Unit/Core/Fixtures/test_extension/composer.json index fb6d1c88d458..215103bef474 100644 --- a/typo3/sysext/core/Tests/Unit/Core/Fixtures/test_extension/composer.json +++ b/typo3/sysext/core/Tests/Unit/Core/Fixtures/test_extension/composer.json @@ -15,6 +15,6 @@ "psr-4": { "TYPO3\\CMS\\TestExtension\\": "Classes/" }, - "classmap": ["Resources/PHP/"] + "classmap": ["Resources/PHP/Test.php"] } } -- GitLab