[BUGFIX] Prevent double slash in canonicalizeAndCheckFolderIdentifier 43/36543/6
authorSascha Egerer <sascha.egerer@dkd.de>
Sat, 31 Jan 2015 20:45:39 +0000 (21:45 +0100)
committerWouter Wolters <typo3@wouterwolters.nl>
Mon, 2 Feb 2015 20:20:52 +0000 (21:20 +0100)
If the value given to AbstractHierarchicalFilesystemDriver->
canonicalizeAndCheckFolderIdentifier()
is '.' the return was '//' but should be '/'.

Resolves: #64706
Releases: master
Change-Id: I63900c44be3180b0a9b8e31d89c6c896382db6b7
Reviewed-on: http://review.typo3.org/36543
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>
typo3/sysext/core/Classes/Resource/Driver/AbstractHierarchicalFilesystemDriver.php
typo3/sysext/core/Tests/Unit/Resource/Driver/AbstractHierarchicalFilesystemDriverTest.php [new file with mode: 0644]

index 11be436..3f901e8 100644 (file)
@@ -16,8 +16,6 @@ namespace TYPO3\CMS\Core\Resource\Driver;
 
 /**
  * Class AbstractHierarchicalFilesystemDriver
- *
- * @package TYPO3\CMS\Core\Resource\Driver
  */
 abstract class AbstractHierarchicalFilesystemDriver extends AbstractDriver {
 
@@ -78,7 +76,7 @@ abstract class AbstractHierarchicalFilesystemDriver extends AbstractDriver {
                if ($folderPath === '/') {
                        $canonicalizedIdentifier = $folderPath;
                } else {
-                       $canonicalizedIdentifier = $this->canonicalizeAndCheckFileIdentifier($folderPath) . '/';
+                       $canonicalizedIdentifier = rtrim($this->canonicalizeAndCheckFileIdentifier($folderPath), '/') . '/';
                }
                return $canonicalizedIdentifier;
        }
diff --git a/typo3/sysext/core/Tests/Unit/Resource/Driver/AbstractHierarchicalFilesystemDriverTest.php b/typo3/sysext/core/Tests/Unit/Resource/Driver/AbstractHierarchicalFilesystemDriverTest.php
new file mode 100644 (file)
index 0000000..e4ace59
--- /dev/null
@@ -0,0 +1,131 @@
+<?php
+namespace TYPO3\CMS\Core\Tests\Unit\Resource\Driver;
+
+/*
+ * This file is part of the TYPO3 CMS project.
+ *
+ * It is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License, either version 2
+ * of the License, or any later version.
+ *
+ * For the full copyright and license information, please read the
+ * LICENSE.txt file that was distributed with this source code.
+ *
+ * The TYPO3 project - inspiring people to share!
+ */
+
+use TYPO3\CMS\Core\Tests\Unit\Resource\BaseTestCase;
+use TYPO3\CMS\Core\Resource\Driver\AbstractHierarchicalFilesystemDriver;
+
+/**
+ * Test case
+ */
+class AbstractHierarchicalFilesystemDriverTest extends BaseTestCase {
+
+       /**
+        * @var AbstractHierarchicalFilesystemDriver|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface
+        */
+       protected $subject = NULL;
+
+       protected function setUp() {
+               parent::setUp();
+               $this->subject = $this->getAccessibleMockForAbstractClass(AbstractHierarchicalFilesystemDriver::class, array(), '', FALSE);
+       }
+
+       /**
+        * @test
+        * @dataProvider canonicalizeAndCheckFileIdentifierCanonicalizesPathDataProvider
+        * @param string $expectedPath
+        * @param string $fileIdentifier
+        */
+       public function canonicalizeAndCheckFileIdentifierCanonicalizesPath($expectedPath, $fileIdentifier) {
+               $this->assertSame($expectedPath, $this->subject->_callRef('canonicalizeAndCheckFileIdentifier', $fileIdentifier));
+       }
+
+       /**
+        * @return array
+        */
+       public function canonicalizeAndCheckFileIdentifierCanonicalizesPathDataProvider() {
+               return array(
+                       'File path gets leading slash' => array(
+                               '/foo.php',
+                               'foo.php',
+                       ),
+                       'Absolute path to file is not modified' => array(
+                               '/bar/foo.php',
+                               '/bar/foo.php',
+                       ),
+                       'Relative path to file gets leading slash' => array(
+                               '/bar/foo.php',
+                               'bar/foo.php',
+                       ),
+                       'Empty string is returned as empty string' => array(
+                               '',
+                               '',
+                       ),
+                       'Double slashes in path are removed' => array(
+                               '/bar/foo.php',
+                               '/bar//foo.php',
+                       ),
+                       'Trailing point in path is removed' => array(
+                               '/foo.php',
+                               './foo.php',
+                       ),
+                       'Point is replaced by slash' => array(
+                               '/',
+                               '.',
+                       ),
+                       './ becomes /' => array(
+                               '/',
+                               './',
+                       )
+               );
+       }
+
+       /**
+        * @test
+        * @dataProvider canonicalizeAndCheckFolderIdentifierCanonicalizesFolderIdentifierDataProvider
+        * @param string $expectedPath
+        * @param string $identifier
+        */
+       public function canonicalizeAndCheckFolderIdentifierCanonicalizesFolderIdentifier($expectedPath, $identifier) {
+               $this->assertSame($expectedPath, $this->subject->_callRef('canonicalizeAndCheckFolderIdentifier', $identifier));
+       }
+
+       /**
+        * @return array
+        */
+       public function canonicalizeAndCheckFolderIdentifierCanonicalizesFolderIdentifierDataProvider() {
+               return array(
+                       'Empty string results in slash' => array(
+                               '/',
+                               '',
+                       ),
+                       'Single point results in slash' => array(
+                               '/',
+                               '.',
+                       ),
+                       'Single slash results in single slash' => array(
+                               '/',
+                               '/',
+                       ),
+                       'Double slash results in single slash' => array(
+                               '/',
+                               '//',
+                       ),
+                       'Absolute folder paths without trailing slash gets a trailing slash' => array(
+                               '/foo/',
+                               '/foo',
+                       ),
+                       'Absolute path with trailing and leading slash is not modified' => array(
+                               '/foo/',
+                               '/foo/',
+                       ),
+                       'Relative path to folder becomes absolute path with trailing slash' => array(
+                               '/foo/',
+                               'foo/',
+                       ),
+               );
+       }
+
+}