[BUGFIX] Add check for valid directory name for TCA select fileFolder 99/50699/4
authorAnja Leichsenring <aleichsenring@ab-softlab.de>
Thu, 17 Nov 2016 16:29:43 +0000 (17:29 +0100)
committerJan Helke <typo3@helke.de>
Fri, 18 Nov 2016 20:23:11 +0000 (21:23 +0100)
If an invalid extension name is passed to a 'EXT:...' path, the
GeneralUtility::getFileAbsFileName function returns an empty string.
This results in a scan of '\' in the first place, and the resulting
error is not helpful for finding the source of the missing icons
in the TCA select box.
A check for a valid directory name and an exception in case of
failure will help the situation.

Resolves: #78737
Releases: master, 7.6
Change-Id: I9d5159eac9b511e879144789eecb40eafcc0288c
Reviewed-on: https://review.typo3.org/50699
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Jan Helke <typo3@helke.de>
Tested-by: Jan Helke <typo3@helke.de>
typo3/sysext/backend/Classes/Form/FormDataProvider/AbstractItemProvider.php
typo3/sysext/backend/Tests/Unit/Form/FormDataProvider/TcaSelectItemsTest.php

index f9862e4..03b1900 100644 (file)
@@ -390,6 +390,7 @@ abstract class AbstractItemProvider
      * @param string $fieldName Current handle field name
      * @param array $items Incoming items
      * @return array Modified item array
+     * @throws \RuntimeException
      */
     protected function addItemsFromFolder(array $result, $fieldName, array $items)
     {
@@ -399,8 +400,14 @@ abstract class AbstractItemProvider
             return $items;
         }
 
-        $fileFolder = $result['processedTca']['columns'][$fieldName]['config']['fileFolder'];
-        $fileFolder = GeneralUtility::getFileAbsFileName($fileFolder);
+        $fileFolderRaw = $result['processedTca']['columns'][$fieldName]['config']['fileFolder'];
+        $fileFolder = GeneralUtility::getFileAbsFileName($fileFolderRaw);
+        if ($fileFolder === '') {
+            throw new \RuntimeException(
+                'Invalid folder given for item processing: ' . $fileFolderRaw . ' for table ' . $result['tableName'] . ', field ' . $fieldName,
+                1479399227
+            );
+        }
         $fileFolder = rtrim($fileFolder, '/') . '/';
 
         if (@is_dir($fileFolder)) {
index 668b37a..a26b9f0 100644 (file)
@@ -1251,6 +1251,32 @@ class TcaSelectItemsTest extends UnitTestCase
     /**
      * @test
      */
+    public function addDataThrowsExceptionForInvalidFileFolder()
+    {
+        $input = [
+            'tableName' => 'aTable',
+            'databaseRow' => [],
+            'processedTca' => [
+                'columns' => [
+                    'aField' => [
+                        'config' => [
+                            'type' => 'select',
+                            'renderType' => 'selectSingle',
+                            'fileFolder' => 'EXT:non_existing/Resources/Public/',
+                        ],
+                    ],
+                ],
+            ],
+        ];
+
+        $this->expectException(\RuntimeException::class);
+        $this->expectExceptionCode(1479399227);
+        $this->subject->addData($input);
+    }
+
+    /**
+     * @test
+     */
     public function addDataAddsItemsByAddItemsFromPageTsConfig()
     {
         $input = [