[BUGFIX] Correct storage selection (follow-up) 71/24071/2
authorErnesto Baschny <ernst@cron-it.de>
Thu, 26 Sep 2013 14:44:59 +0000 (16:44 +0200)
committerStefan Neufeind <typo3.neufeind@speedpartner.de>
Sat, 9 Nov 2013 15:44:58 +0000 (16:44 +0100)
The new matching did not consider Windows paths names as the
previous version did. Using PathUtility is safer.

Releases: 6.2, 6.1, 6.0
Resolves: #52173
Change-Id: Ib0454a468bb93f5baab9677ffafc86efd0f1ae27
Reviewed-on: https://review.typo3.org/24071
Reviewed-by: Wouter Wolters
Reviewed-by: Philipp Gampe
Tested-by: Philipp Gampe
Reviewed-by: Steffen Ritter
Tested-by: Steffen Ritter
Reviewed-by: Stefan Neufeind
Tested-by: Stefan Neufeind
typo3/sysext/core/Classes/Resource/ResourceFactory.php
typo3/sysext/core/Tests/Unit/Resource/ResourceFactoryTest.php

index 74d6e2c..9ebd3c3 100644 (file)
@@ -182,12 +182,10 @@ class ResourceFactory implements \TYPO3\CMS\Core\SingletonInterface {
                $bestMatchStorageUid = 0;
                $bestMatchLength = 0;
                foreach ($this->localDriverStorageCache as $storageUid => $basePath) {
-                       $matchLength = strlen($basePath);
-                       if (substr($localPath, 0, $matchLength) !== $basePath) {
-                               continue;
-                       }
+                       $matchLength = strlen(PathUtility::getCommonPrefix(array($basePath, $localPath)));
+                       $basePathLength = strlen($basePath);
 
-                       if ($matchLength > $bestMatchLength) {
+                       if ($matchLength >= $basePathLength && $matchLength > $bestMatchLength) {
                                $bestMatchStorageUid = intval($storageUid);
                                $bestMatchLength = $matchLength;
                        }
index 8dd4cee..1c00265 100644 (file)
@@ -197,6 +197,11 @@ class FactoryTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                                'uploads/test/dummy.png',
                                2
                        ),
+                       'FindStorageFromWindowsPath' => array(
+                               array(1 => 'fileadmin/', 2 => 'uploads/test/'),
+                               'uploads\\test\\dummy.png',
+                               2
+                       ),
                );
        }
 }