Issue Bug Closed

#65765findBestMatchingStorageByLocalPath produces wrong identifier

nemo m 03/16/15, 13:41 updated 06/18/15, 11:20

Description

[`ResourceFactory->findBestMatchingStorageByLocalPath()`](https://github.com/TYPO3/TYPO3.CMS/blob/TYPO3_6-2/typo3/sysext/core/Classes/Resource/ResourceFactory.php#L194) produces a wrong identifier.

Example input:

    fileadmin/_processed_/csm_2048_d103438c3b.jpg

Expected output (via output parameter):

    /_processed_/csm_2048_d103438c3b.jpg

Actual output:

    _processed_/csm_2048_d103438c3b.jpg

The missing slash leads to files not being found. This issue occurs due to the following cropping:

       if ($bestMatchStorageUid !== 0) {
        $localPath = substr($localPath, $bestMatchLength);
    }

Example:

File `fileadmin/foo` is requested, the local storage `basePath` is `fileadmin/`, `PathUtility::getCommonPrefix(array($basePath, $localPath))` therefore returns `fileadmin/` as common prefix.

This leads to the slash being removed. In my opinion this code is bugged.

Since `PathUtility::getCommonPrefix()` seems to always produce at least `/`, the code should be

     $matchLength = strlen(PathUtility::getCommonPrefix(array($basePath, $localPath))) - 1;

Instead of

     $matchLength = strlen(PathUtility::getCommonPrefix(array($basePath, $localPath)));

IMO.

Reviews 0

No change resolves or names this issue in its commit message, and no comment links one.