[BUGFIX] Remove trailing slash from autoload information files 69/43669/3
authorHelmut Hummel <helmut.hummel@typo3.org>
Wed, 30 Sep 2015 18:27:35 +0000 (20:27 +0200)
committerGeorg Ringer <georg.ringer@gmail.com>
Thu, 1 Oct 2015 04:53:07 +0000 (06:53 +0200)
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>
typo3/sysext/core/Classes/Core/ClassLoadingInformationGenerator.php
typo3/sysext/core/Tests/Unit/Core/ClassLoadingInformationGeneratorTest.php
typo3/sysext/core/Tests/Unit/Core/Fixtures/test_extension/composer.json

index 05e5116..7c4a9a7 100644 (file)
@@ -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)), '/');
                }
index 7015471..591f622 100644 (file)
@@ -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']);
        }
 
index fb6d1c8..215103b 100644 (file)
@@ -15,6 +15,6 @@
                "psr-4": {
                        "TYPO3\\CMS\\TestExtension\\": "Classes/"
                },
-               "classmap": ["Resources/PHP/"]
+               "classmap": ["Resources/PHP/Test.php"]
        }
 }