[BUGFIX] Ensure new deep dirs don't contain double slashes 99/36399/8
authorThomas Deuling <tdeuling@gmail.com>
Fri, 30 Jan 2015 10:06:42 +0000 (11:06 +0100)
committerWouter Wolters <typo3@wouterwolters.nl>
Sat, 28 Feb 2015 16:28:53 +0000 (17:28 +0100)
The method of GeneralUtility::mkdir_deep has two parameters, which are
concatenated. This could end up in a double slashes. To prevent that,
the parameters are modified to concat them with only one slash.

Additionally fix a Bug with double slash in FileStreamWrapper.

Resolves: #63920
Releases: master, 6.2
Change-Id: I2d15f6c33550f9045db9b7730f7b074ae54a18dc
Reviewed-on: http://review.typo3.org/36399
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Stefan Neufeind <typo3.neufeind@speedpartner.de>
Tested-by: Stefan Neufeind <typo3.neufeind@speedpartner.de>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
typo3/sysext/core/Classes/Utility/GeneralUtility.php
typo3/sysext/core/Tests/FileStreamWrapper.php
typo3/sysext/core/Tests/Unit/Utility/GeneralUtilityTest.php

index 43e3069..7e9e5c4 100755 (executable)
@@ -2725,7 +2725,8 @@ Connection: close
                if (!is_string($deepDirectory)) {
                        throw new \InvalidArgumentException('The specified directory is of type "' . gettype($deepDirectory) . '" but a string is expected.', 1303662956);
                }
-               $fullPath = $directory . $deepDirectory;
+               // Ensure there is only one slash
+               $fullPath = rtrim($directory, '/') . '/' . ltrim($deepDirectory, '/');
                if ($fullPath !== '' && !is_dir($fullPath)) {
                        $firstCreatedPath = self::createDirectoryPath($fullPath);
                        if ($firstCreatedPath !== '') {
index b262bc3..a4b6f93 100644 (file)
@@ -142,7 +142,7 @@ class FileStreamWrapper {
                        return $path;
                }
 
-               $newPath = substr($path, strlen(self::$rootPath));
+               $newPath = ltrim(substr($path, strlen(self::$rootPath)), '/');
                foreach (self::$overlayPaths as $overlay => $replace) {
                        if (strpos($newPath, $overlay) === 0) {
                                $newPath = $replace . substr($newPath, strlen($overlay));
index 31d0325..7a010f1 100644 (file)
@@ -19,6 +19,7 @@ use TYPO3\CMS\Core\Utility;
 use \org\bovigo\vfs\vfsStream;
 use \org\bovigo\vfs\vfsStreamDirectory;
 use \org\bovigo\vfs\vfsStreamWrapper;
+use TYPO3\CMS\Core\Tests\FileStreamWrapper;
 
 /**
  * Testcase for class \TYPO3\CMS\Core\Utility\GeneralUtility
@@ -2824,6 +2825,31 @@ class GeneralUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
        }
 
        /**
+        * Data provider for mkdirDeepCreatesDirectoryWithDoubleSlashes.
+        * @return array
+        */
+       public function mkdirDeepCreatesDirectoryWithAndWithoutDoubleSlashesDataProvider() {
+               return array(
+                       'no double slash if concatenated with PATH_site' => array('fileadmin/testDir1'),
+                       'double slash if concatenated with PATH_site' => array('/fileadmin/testDir2'),
+               );
+       }
+
+       /**
+        * @test
+        * @dataProvider mkdirDeepCreatesDirectoryWithAndWithoutDoubleSlashesDataProvider
+        */
+       public function mkdirDeepCreatesDirectoryWithDoubleSlashes($directoryToCreate) {
+               vfsStream::setup();
+               // Load fixture files and folders from disk
+               FileStreamWrapper::init(PATH_site);
+               FileStreamWrapper::registerOverlayPath('fileadmin', 'vfs://root/fileadmin', TRUE);
+               Utility\GeneralUtility::mkdir_deep(PATH_site, $directoryToCreate);
+               $this->assertTrue(is_dir(PATH_site . $directoryToCreate));
+               FileStreamWrapper::destroy();
+       }
+
+       /**
         * @test
         */
        public function mkdirDeepFixesPermissionsOfCreatedDirectory() {