[BUGFIX] PathUtility::get...FileOrPath() does not work with basepath 67/29467/4
authorMarkus Klein <klein.t3@mfc-linz.at>
Mon, 14 Apr 2014 22:50:49 +0000 (00:50 +0200)
committerMarkus Klein <klein.t3@mfc-linz.at>
Thu, 22 May 2014 12:09:50 +0000 (14:09 +0200)
PathUtility::getAbsolutePathOfRelativeReferencedFileOrPath()
Add a check to the function to identify a given basepath as described
in the function header.

Resolves: #57918
Releases: 6.2, 6.1
Change-Id: I8de12cb917b2f32490bb160686ce06a036abfd85
Reviewed-on: https://review.typo3.org/29467
Reviewed-by: Wouter Wolters
Tested-by: Wouter Wolters
Reviewed-by: Markus Klein
Tested-by: Markus Klein
typo3/sysext/core/Classes/Utility/PathUtility.php
typo3/sysext/core/Tests/Unit/Utility/PathUtilityTest.php

index c5f0892..762f1b0 100644 (file)
@@ -233,7 +233,8 @@ class PathUtility {
         */
        static public function getAbsolutePathOfRelativeReferencedFileOrPath($baseFilenameOrPath, $includeFileName) {
                $fileName = static::basename($includeFileName);
-               $newDir = static::getCanonicalPath(static::dirname($baseFilenameOrPath) . '/' . static::dirname($includeFileName));
+               $basePath = substr($baseFilenameOrPath, -1) === '/' ? $baseFilenameOrPath : static::dirname($baseFilenameOrPath);
+               $newDir = static::getCanonicalPath($basePath . '/' . static::dirname($includeFileName));
                // Avoid double slash on empty path
                $result = (($newDir !== '/') ? $newDir : '') . '/' . $fileName;
                return $result;
index ca3514f..c047f92 100644 (file)
@@ -227,7 +227,17 @@ class PathUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                                '/abc/one.txt',
                                '../../two.txt',
                                '/two.txt',
-                       )
+                       ),
+                       'base folder with same folder path' => array(
+                               '/abc/',
+                               './two.txt',
+                               '/abc/two.txt'
+                       ),
+                       'base folder with parent folder path' => array(
+                               '/abc/bar/',
+                               '../foo.txt',
+                               '/abc/foo.txt'
+                       ),
                );
        }