[BUGFIX] Use return values of array_map in local driver 40/28940/3
authorAlexander Stehlik <alexander.stehlik@gmail.com>
Fri, 28 Mar 2014 15:52:31 +0000 (16:52 +0100)
committerMarkus Klein <klein.t3@mfc-linz.at>
Mon, 7 Apr 2014 18:50:23 +0000 (20:50 +0200)
The LocalDriver will now use the return values of array_map calls in
createFolder() and determineBaseUrl() so that the values are really
sanitized / url encoded.

Resolves: #57415
Releases: 6.2
Change-Id: I8aa1a79c6e4a7fe6c2d82ec66c12338e75a35872
Reviewed-on: https://review.typo3.org/28940
Reviewed-by: Frans Saris
Tested-by: Frans Saris
Reviewed-by: Markus Klein
Tested-by: Markus Klein
typo3/sysext/core/Classes/Resource/Driver/LocalDriver.php
typo3/sysext/core/Tests/Unit/Resource/Driver/LocalDriverTest.php

index e6a3955..5a19f63 100644 (file)
@@ -142,7 +142,7 @@ class LocalDriver extends AbstractHierarchicalFilesystemDriver {
                                $temporaryBaseUri = rtrim(\TYPO3\CMS\Core\Utility\PathUtility::stripPathSitePrefix($this->absoluteBasePath), '/');
                                if ($temporaryBaseUri !== '') {
                                        $uriParts = explode('/', $temporaryBaseUri);
-                                       array_map('rawurlencode', $uriParts);
+                                       $uriParts = array_map('rawurlencode', $uriParts);
                                        $temporaryBaseUri = implode('/', $uriParts) . '/';
                                }
                                $this->baseUri = $temporaryBaseUri;
@@ -244,7 +244,7 @@ class LocalDriver extends AbstractHierarchicalFilesystemDriver {
                        GeneralUtility::mkdir($this->getAbsoluteBasePath() . $newIdentifier);
                } else {
                        $parts = GeneralUtility::trimExplode('/', $newFolderName);
-                       array_map(array($this, 'sanitizeFileName'), $parts);
+                       $parts = array_map(array($this, 'sanitizeFileName'), $parts);
                        $newFolderName = implode('/', $parts);
                        $newIdentifier = $parentFolderIdentifier . $newFolderName . '/';
                        GeneralUtility::mkdir_deep($this->getAbsoluteBasePath() . $parentFolderIdentifier, $newFolderName);
index aae8770..6d32063 100644 (file)
@@ -141,6 +141,39 @@ class LocalDriverTest extends \TYPO3\CMS\Core\Tests\Unit\Resource\BaseTestCase {
        /**
         * @test
         */
+       public function createFolderRecursiveSanitizesFilename() {
+               /** @var \TYPO3\CMS\Core\Resource\Driver\LocalDriver|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface $driver */
+               $driver = $this->createDriverFixture(array(), array('sanitizeFilename'));
+               $driver->expects($this->exactly(2))
+                       ->method('sanitizeFileName')
+                       ->will(
+                               $this->returnValue('sanitized')
+                       );
+               $driver->createFolder('newFolder/andSubfolder', '/', TRUE);
+               $this->assertFileExists($this->getUrlInMount('/sanitized/sanitized/'));
+       }
+
+       /**
+        * @test
+        */
+       public function determineBaseUrlUrlEncodesUriParts() {
+               /** @var \TYPO3\CMS\Core\Resource\Driver\LocalDriver|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface $driver */
+               $driver = $this->getAccessibleMock('TYPO3\\CMS\\Core\\Resource\\Driver\\LocalDriver', array('hasCapability'), array(), '', FALSE);
+               $driver->expects($this->once())
+                       ->method('hasCapability')
+                       ->with(\TYPO3\CMS\Core\Resource\ResourceStorage::CAPABILITY_PUBLIC)
+                       ->will(
+                               $this->returnValue(TRUE)
+                       );
+               $driver->_set('absoluteBasePath', PATH_site . 'un encö/ded %path/');
+               $driver->_call('determineBaseUrl');
+               $baseUri = $driver->_get('baseUri');
+               $this->assertEquals(rawurlencode('un encö') . '/' . rawurlencode('ded %path') . '/', $baseUri);
+       }
+
+       /**
+        * @test
+        */
        public function getDefaultFolderReturnsFolderForUserUploadPath() {
                $fixture = $this->createDriverFixture();
                $folderIdentifier = $fixture->getDefaultFolder();