[BUGFIX] Path utility resolves incorrect
authorIngmar Schlecht <ingmar@typo3.org>
Fri, 20 Apr 2012 15:58:17 +0000 (17:58 +0200)
committerTolleiv Nietsch <tolleiv.nietsch@typo3.org>
Sat, 21 Apr 2012 09:31:41 +0000 (11:31 +0200)
The path utility resolves incorrect if target path is
only one level below source path.

Example:
From "mypath/" to "mypath/t3lib/" it's just
"t3lib/" instead of "../t3lib/".

Change-Id: I11c4734a4b64d73773e58d6a2c2c0b218c09109a
Fixes: #36385
Releases: 6.0, 4.7
Reviewed-on: http://review.typo3.org/10653
Reviewed-by: Oliver Hader
Tested-by: Oliver Hader
Reviewed-by: Tolleiv Nietsch
Tested-by: Tolleiv Nietsch
t3lib/utility/class.t3lib_utility_path.php
tests/t3lib/utility/class.t3lib_utility_pathTest.php

index 5472977..0bc7299 100644 (file)
@@ -68,6 +68,7 @@ final class t3lib_utility_Path {
                                $commonPrefixLength = strlen($commonPrefix);
                                $resolvedSourcePath = '';
                                $resolvedTargetPath = '';
+                               $sourcePathSteps = 0;
 
                                if (strlen($sourcePath) > $commonPrefixLength) {
                                        $resolvedSourcePath = (string) substr($sourcePath, $commonPrefixLength);
@@ -76,7 +77,10 @@ final class t3lib_utility_Path {
                                        $resolvedTargetPath = (string) substr($targetPath, $commonPrefixLength);
                                }
 
-                               $sourcePathSteps = count(explode(DIRECTORY_SEPARATOR, $resolvedSourcePath));
+                               if ($resolvedSourcePath !== '') {
+                                       $sourcePathSteps = count(explode(DIRECTORY_SEPARATOR, $resolvedSourcePath));
+                               }
+
                                $relativePath = self::sanitizeTrailingSeparator(
                                        str_repeat('../', $sourcePathSteps) .
                                        str_replace(DIRECTORY_SEPARATOR, '/', $resolvedTargetPath)
index a307c4a..2176eb9 100644 (file)
@@ -124,6 +124,16 @@ class t3lib_utility_PathTest extends tx_phpunit_testcase {
                                '../t3lib/'
                        ),
                        array(
+                               PATH_site,
+                               PATH_site . 't3lib/',
+                               't3lib/'
+                       ),
+                       array(
+                               PATH_site.'t3lib/',
+                               PATH_site . 't3lib/stddb/',
+                               'stddb/'
+                       ),
+                       array(
                                PATH_site . 'typo3/sysext/cms/',
                                PATH_site . 't3lib/utility/',
                                '../../../t3lib/utility/'