[BUGFIX] Extend ResourceStorage API to check for applied filters 44/56844/3
authorNicole Cordes <typo3@cordes.co>
Thu, 3 May 2018 10:21:59 +0000 (12:21 +0200)
committerJigal van Hemert <jigal.van.hemert@typo3.org>
Tue, 5 Jun 2018 19:20:56 +0000 (21:20 +0200)
Currently only the DriverInterface cares about applied filters.
The ResourceStorage received a new API function to validate a file or
folder object against applied filters as well. This ensures proper
validation for objects fetched without driver calls.

Resolves: #84908
Releases: master, 8.7
Change-Id: I5e8d35215c99aacfb330fe0eb8cfd9259b9a4199
Reviewed-on: https://review.typo3.org/56844
Reviewed-by: Mathias Schreiber <mathias.schreiber@typo3.com>
Tested-by: Mathias Schreiber <mathias.schreiber@typo3.com>
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Jigal van Hemert <jigal.van.hemert@typo3.org>
Tested-by: Jigal van Hemert <jigal.van.hemert@typo3.org>
typo3/sysext/core/Classes/Resource/FileRepository.php
typo3/sysext/core/Classes/Resource/ResourceStorage.php

index bd5f70b..7a571d1 100644 (file)
@@ -173,7 +173,8 @@ class FileRepository extends AbstractRepository
         /** @var ResourceFactory $fileFactory */
         $fileFactory = GeneralUtility::makeInstance(ResourceFactory::class);
 
-        $folders = $folder->getStorage()->getFoldersInFolder($folder, 0, 0, true, true);
+        $storage = $folder->getStorage();
+        $folders = $storage->getFoldersInFolder($folder, 0, 0, true, true);
         $folders[$folder->getIdentifier()] = $folder;
 
         $fileRecords = $this->getFileIndexRepository()->findByFolders($folders, false, $fileName);
@@ -182,7 +183,10 @@ class FileRepository extends AbstractRepository
         $files = [];
         foreach ($fileRecords as $fileRecord) {
             try {
-                $files[] = $fileFactory->getFileObject($fileRecord['uid'], $fileRecord);
+                $file = $fileFactory->getFileObject($fileRecord['uid'], $fileRecord);
+                if ($storage->checkFileAndFolderNameFilters($file)) {
+                    $files[] = $file;
+                }
             } catch (Exception\FileDoesNotExistException $ignoredException) {
                 continue;
             }
index 56c8cb3..38bf6c8 100644 (file)
@@ -710,6 +710,32 @@ class ResourceStorage implements ResourceStorageInterface
     }
 
     /**
+     * @param ResourceInterface $fileOrFolder
+     * @return bool
+     */
+    public function checkFileAndFolderNameFilters(ResourceInterface $fileOrFolder)
+    {
+        foreach ($this->fileAndFolderNameFilters as $filter) {
+            if (is_callable($filter)) {
+                $result = call_user_func($filter, $fileOrFolder->getName(), $fileOrFolder->getIdentifier(), $fileOrFolder->getParentFolder()->getIdentifier(), [], $this->driver);
+                // We have to use -1 as the „don't include“ return value, as call_user_func() will return FALSE
+                // If calling the method succeeded and thus we can't use that as a return value.
+                if ($result === -1) {
+                    return false;
+                }
+                if ($result === false) {
+                    throw new \RuntimeException(
+                        'Could not apply file/folder name filter ' . $filter[0] . '::' . $filter[1],
+                        1525342106
+                    );
+                }
+            }
+        }
+
+        return true;
+    }
+
+    /**
      * If the fileName is given, checks it against the
      * TYPO3_CONF_VARS[BE][fileDenyPattern] + and if the file extension is allowed.
      *