[BUGFIX] Catch InvalidPathException for FileStorages 51/55551/3
authorMathias Schreiber <mathias.schreiber@typo3.org>
Sun, 4 Feb 2018 16:06:12 +0000 (17:06 +0100)
committerAndreas Fernandez <a.fernandez@scripting-base.de>
Sun, 4 Feb 2018 18:04:29 +0000 (19:04 +0100)
Editing faulty FileStorages is possible again due to catching the
respective exception and piping it into a FlashMessage

Resolves: #83762
Releases: master, 8.7
Change-Id: I5081d86fd73076359b1d9eba954ba07c50bcb7b2
Reviewed-on: https://review.typo3.org/55551
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Tested-by: Andreas Fernandez <a.fernandez@scripting-base.de>
typo3/sysext/core/Classes/Resource/Service/UserStorageCapabilityService.php
typo3/sysext/lang/Resources/Private/Language/locallang_core.xlf

index 65727fd..564350f 100644 (file)
@@ -18,6 +18,7 @@ use TYPO3\CMS\Core\Localization\LanguageService;
 use TYPO3\CMS\Core\Messaging\FlashMessage;
 use TYPO3\CMS\Core\Messaging\FlashMessageQueue;
 use TYPO3\CMS\Core\Messaging\FlashMessageService;
+use TYPO3\CMS\Core\Resource\Exception\InvalidPathException;
 use TYPO3\CMS\Core\Resource\ResourceFactory;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 
@@ -42,25 +43,34 @@ class UserStorageCapabilityService
 
         // Makes sure the storage object can be retrieved which is not the case when new storage.
         if ((int)$propertyArray['row']['uid'] > 0) {
-            $storage = ResourceFactory::getInstance()->getStorageObject($fileRecord['uid']);
-            $storageRecord = $storage->getStorageRecord();
-            $isPublic = $storage->isPublic() && $storageRecord['is_public'];
+            /** @var LanguageService $lang */
+            $lang = $GLOBALS['LANG'];
+            /** @var $flashMessageService FlashMessageService */
+            $flashMessageService = GeneralUtility::makeInstance(FlashMessageService::class);
+            /** @var $defaultFlashMessageQueue FlashMessageQueue */
+            $defaultFlashMessageQueue = $flashMessageService->getMessageQueueByIdentifier();
+            try {
+                $storage = ResourceFactory::getInstance()->getStorageObject($fileRecord['uid']);
+                $storageRecord = $storage->getStorageRecord();
+                $isPublic = $storage->isPublic() && $storageRecord['is_public'];
+            } catch (InvalidPathException $e) {
+                $message = GeneralUtility::makeInstance(
+                    FlashMessage::class,
+                    $lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:filestorage.invalidpathexception.message'),
+                    $lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:filestorage.invalidpathexception.title'),
+                    FlashMessage::ERROR
+                );
+                $defaultFlashMessageQueue->enqueue($message);
+            }
 
             // Display a warning to the BE User in case settings is not inline with storage capability.
             if ($storageRecord['is_public'] && !$storage->isPublic()) {
-                /** @var LanguageService $lang */
-                $lang = $GLOBALS['LANG'];
                 $message = GeneralUtility::makeInstance(
                     FlashMessage::class,
                     $lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:warning.message.storage_is_no_public'),
                     $lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:warning.header.storage_is_no_public'),
                     FlashMessage::WARNING
                 );
-
-                /** @var $flashMessageService FlashMessageService */
-                $flashMessageService = GeneralUtility::makeInstance(FlashMessageService::class);
-                /** @var $defaultFlashMessageQueue FlashMessageQueue */
-                $defaultFlashMessageQueue = $flashMessageService->getMessageQueueByIdentifier();
                 $defaultFlashMessageQueue->enqueue($message);
             }
         }
index f800511..cc9a929 100644 (file)
@@ -1303,6 +1303,12 @@ Do you want to refresh it now?</source>
                        <trans-unit id="pageTranslation">
                                <source>Page Translation</source>
                        </trans-unit>
+                       <trans-unit id="filestorage.invalidpathexception.title">
+                               <source>Error in Path</source>
+                       </trans-unit>
+                       <trans-unit id="filestorage.invalidpathexception.message">
+                               <source>You entered an invalid path for this File Storage. Note that "../" and "//" are not allowed when using an absolute path.</source>
+                       </trans-unit>
                </body>
        </file>
 </xliff>