[BUGFIX] Preview images not rendered in Web > Page view on Windows systems
authorNicole Cordes <n.cordes@biz-design.biz>
Fri, 21 Sep 2012 19:39:34 +0000 (21:39 +0200)
committerHelmut Hummel <helmut.hummel@typo3.org>
Sun, 30 Sep 2012 13:41:09 +0000 (15:41 +0200)
In Web > Page view the preview images are not rendered on Windows systems.
This is due to failing functions in class
TYPO3\CMS\Core\Utility\PathUtility. Basically it's an issue with forward
and backward slashes. In the class the constance DIRECTORY_SEPARATOR is
used which is on Windows systems a backward slash. Normally paths in TYPO3
are converted to use forward slashes and here is the existing problem.

This patch removes the constance in some functions (which are nessessary
for preview images) and makes sure all pathes are converted to unix style.
Than processing can use forward shlashes and carry on.

Change-Id: If7b443e5180e26ceb089a5b47c1631c4c7eb21c1
Fixes: #41204
Releases: 6.0, 4.7
Reviewed-on: http://review.typo3.org/14873
Reviewed-by: Anja Leichsenring
Tested-by: Anja Leichsenring
Reviewed-by: Georg Ringer
Tested-by: Georg Ringer
Reviewed-by: Simon Schaufelberger
Tested-by: Simon Schaufelberger
Reviewed-by: Helmut Hummel
Tested-by: Helmut Hummel
typo3/sysext/core/Classes/Utility/PathUtility.php
typo3/sysext/core/Tests/Unit/Utility/PathUtilityTest.php

index 1f7f5b2..7156ea4 100644 (file)
@@ -56,8 +56,8 @@ class PathUtility {
         */
        static public function getRelativePath($sourcePath, $targetPath) {
                $relativePath = NULL;
-               $sourcePath = rtrim($sourcePath, DIRECTORY_SEPARATOR);
-               $targetPath = rtrim($targetPath, DIRECTORY_SEPARATOR);
+               $sourcePath = rtrim(GeneralUtility::fixWindowsFilePath($sourcePath), '/');
+               $targetPath = rtrim(GeneralUtility::fixWindowsFilePath($targetPath), '/');
                if ($sourcePath !== $targetPath) {
                        $commonPrefix = self::getCommonPrefix(array($sourcePath, $targetPath));
                        if ($commonPrefix !== NULL && \TYPO3\CMS\Core\Utility\GeneralUtility::isAllowedAbsPath($commonPrefix)) {
@@ -72,9 +72,9 @@ class PathUtility {
                                        $resolvedTargetPath = (string) substr($targetPath, $commonPrefixLength);
                                }
                                if ($resolvedSourcePath !== '') {
-                                       $sourcePathSteps = count(explode(DIRECTORY_SEPARATOR, $resolvedSourcePath));
+                                       $sourcePathSteps = count(explode('/', $resolvedSourcePath));
                                }
-                               $relativePath = self::sanitizeTrailingSeparator(str_repeat('../', $sourcePathSteps) . str_replace(DIRECTORY_SEPARATOR, '/', $resolvedTargetPath));
+                               $relativePath = self::sanitizeTrailingSeparator(str_repeat('../', $sourcePathSteps) . $resolvedTargetPath);
                        }
                }
                return $relativePath;
@@ -91,17 +91,18 @@ class PathUtility {
         * @return NULL|string
         */
        static public function getCommonPrefix(array $paths) {
+               $paths = array_map(array('TYPO3\\CMS\\Core\\Utility\\GeneralUtility', 'fixWindowsFilePath'), $paths);
                $commonPath = NULL;
                if (count($paths) === 1) {
                        $commonPath = array_shift($paths);
                } elseif (count($paths) > 1) {
-                       $parts = explode(DIRECTORY_SEPARATOR, array_shift($paths));
+                       $parts = explode('/', array_shift($paths));
                        $comparePath = '';
                        $break = FALSE;
                        foreach ($parts as $part) {
-                               $comparePath .= $part . DIRECTORY_SEPARATOR;
+                               $comparePath .= $part . '/';
                                foreach ($paths as $path) {
-                                       if (strpos($path . DIRECTORY_SEPARATOR, $comparePath) !== 0) {
+                                       if (strpos($path . '/', $comparePath) !== 0) {
                                                $break = TRUE;
                                                break;
                                        }
@@ -113,7 +114,7 @@ class PathUtility {
                        }
                }
                if ($commonPath !== NULL) {
-                       $commonPath = self::sanitizeTrailingSeparator($commonPath, DIRECTORY_SEPARATOR);
+                       $commonPath = self::sanitizeTrailingSeparator($commonPath, '/');
                }
                return $commonPath;
        }
@@ -133,4 +134,4 @@ class PathUtility {
 }
 
 
-?>
\ No newline at end of file
+?>
index 8b73485..879eed8 100644 (file)
@@ -88,6 +88,43 @@ class PathUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                                        '/var/www/myhost.com/t3lib/utility/'
                                ),
                                '/var/www/myhost.com/'
+                       ),
+                       array(
+                               array(
+                                       'C:\\www\\myhost.com\\t3lib\\'
+                               ),
+                               'C:/www/myhost.com/t3lib/'
+                       ),
+                       array(
+                               array(
+                                       'C:\\www\\myhost.com\\t3lib\\',
+                                       'C:\\www\\myhost.com\\t3lib\\'
+                               ),
+                               'C:/www/myhost.com/t3lib/'
+                       ),
+                       array(
+                               array(
+                                       'C:\\www\\myhost.com\\typo3\\',
+                                       'C:\\www\\myhost.com\\t3lib\\'
+                               ),
+                               'C:/www/myhost.com/'
+                       ),
+                       array(
+                               array(
+                                       'C:\\www\\myhost.com\\uploads\\',
+                                       'C:\\www\\myhost.com\\typo3\\',
+                                       'C:\\www\\myhost.com\\t3lib\\'
+                               ),
+                               'C:/www/myhost.com/'
+                       ),
+                       array(
+                               array(
+                                       'C:\\www\\myhost.com\\uploads\\directory\\',
+                                       'C:\\www\\myhost.com\\typo3\\sysext\\',
+                                       'C:\\www\\myhost.com\\typo3\\contrib\\',
+                                       'C:\\www\\myhost.com\\t3lib\\utility\\'
+                               ),
+                               'C:/www/myhost.com/'
                        )
                );
        }
@@ -138,7 +175,7 @@ class PathUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                                PATH_site . 'typo3/sysext/cms/',
                                PATH_site . 't3lib/utility/',
                                '../../../t3lib/utility/'
-                       )
+                       ),
                );
        }
 
@@ -167,4 +204,4 @@ class PathUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
 
 }
 
-?>
\ No newline at end of file
+?>