[BUGFIX] Correct storage selection (common prefixes) 93/23993/2
authorErnesto Baschny <ernst@cron-it.de>
Mon, 23 Sep 2013 08:29:56 +0000 (10:29 +0200)
committerAnja Leichsenring <aleichsenring@ab-softlab.de>
Tue, 24 Sep 2013 08:54:16 +0000 (10:54 +0200)
If there is a local storage "uploads/test/" and a requested file
is in "uploads/other/file.txt", the storage matching will not
consider this storage for this file anymore, although they share a
common prefix, but will use a correct matching storage (e.g. 0).

Releases: 6.2, 6.1, 6.0
Resolves: #52173
Change-Id: Id14ffd6620554c086b6e77dca285ade8dee39ab2
Reviewed-on: https://review.typo3.org/23993
Reviewed-by: Stefan Neufeind
Reviewed-by: Anja Leichsenring
Tested-by: Anja Leichsenring
typo3/sysext/core/Classes/Resource/ResourceFactory.php
typo3/sysext/core/Tests/Unit/Resource/ResourceFactoryTest.php

index 9155c9a..80fb943 100644 (file)
@@ -180,8 +180,11 @@ class ResourceFactory implements \TYPO3\CMS\Core\SingletonInterface {
                $bestMatchStorageUid = 0;
                $bestMatchLength = 0;
                foreach ($this->localDriverStorageCache as $storageUid => $basePath) {
-                       $commonPrefix = PathUtility::getCommonPrefix(array($basePath, $localPath));
-                       $matchLength = strlen($commonPrefix);
+                       $matchLength = strlen($basePath);
+                       if (substr($localPath, 0, $matchLength) !== $basePath) {
+                               continue;
+                       }
+
                        if ($matchLength > $bestMatchLength) {
                                $bestMatchStorageUid = intval($storageUid);
                                $bestMatchLength = $matchLength;
index dfc15ed..97a2553 100644 (file)
@@ -185,7 +185,17 @@ class FactoryTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                                array(1 => 'fileadmin/', 2 => 'fileadmin/public/'),
                                'fileadmin/public/Image.png',
                                2
-                       )
+                       ),
+                       'CommonPrefixButWrongPath' => array(
+                               array(1 => 'fileadmin/', 2 => 'uploads/test/'),
+                               'uploads/bogus/dummy.png',
+                               0
+                       ),
+                       'CommonPrefixRightPath' => array(
+                               array(1 => 'fileadmin/', 2 => 'uploads/test/'),
+                               'uploads/test/dummy.png',
+                               2
+                       ),
                );
        }
 }