[BUGFIX] Throw empty table name exception in TCE GroupElement 91/49091/2
authorPetra Arentzen <typo3@pegu.de>
Fri, 1 Jul 2016 09:16:21 +0000 (11:16 +0200)
committerMarkus Klein <markus.klein@typo3.org>
Tue, 19 Jul 2016 11:28:39 +0000 (13:28 +0200)
Throw an exception if table name is empty after parsing the value
by BackendUtility::splitTable_Uid(). It avoids calling
IconFactory::getIconForRecord() with the invalid parameter $row
and throwing a less specific exception then. Only fields with
TCA Configuration type='group', internal_type='db' and
show_thumbs=TRUE are concerned.

Resolves: #76232
Releases: master, 7.6
Change-Id: I44c52f6ebfdbcfbbd2209890b0458b8126cbeccd
Reviewed-on: https://review.typo3.org/49091
Reviewed-by: Markus Klein <markus.klein@typo3.org>
Tested-by: Markus Klein <markus.klein@typo3.org>
typo3/sysext/backend/Classes/Form/Element/GroupElement.php
typo3/sysext/backend/Tests/Unit/Form/Element/GroupElementTest.php [new file with mode: 0644]

index 206965e..ad5424d 100644 (file)
@@ -34,6 +34,7 @@ class GroupElement extends AbstractFormElement
      * the file system or database can be inserted. Relations.
      *
      * @return array As defined in initializeResultArray() of AbstractNode
+     * @throws \RuntimeException
      */
     public function render()
     {
@@ -273,8 +274,17 @@ class GroupElement extends AbstractFormElement
                 foreach ($temp_itemArray as $dbRead) {
                     $recordParts = explode('|', $dbRead);
                     list($this_table, $this_uid) = BackendUtility::splitTable_Uid($recordParts[0]);
+
                     $itemArray[] = array('table' => $this_table, 'id' => $this_uid);
                     if (!$disabled && $show_thumbs) {
+                        if (empty($this_table)) {
+                            throw new \RuntimeException(
+                                'Table name could not been determined for field "' . $fieldName . '" in table "' . $table . '". ' .
+                                'This should never happen since the table name should have been already prepared in the DataProvider TcaGroup. ' .
+                                'Maybe the prepared values have been set to an invalid value by a user defined data provider.',
+                                1468149217
+                            );
+                        }
                         $rr = BackendUtility::getRecordWSOL($this_table, $this_uid);
                         $thumbnails[] = array(
                             'name' => BackendUtility::getRecordTitle($this_table, $rr, true),
diff --git a/typo3/sysext/backend/Tests/Unit/Form/Element/GroupElementTest.php b/typo3/sysext/backend/Tests/Unit/Form/Element/GroupElementTest.php
new file mode 100644 (file)
index 0000000..b5c37c3
--- /dev/null
@@ -0,0 +1,63 @@
+<?php
+namespace TYPO3\CMS\Backend\Tests\Unit\Form;
+
+/*
+ * This file is part of the TYPO3 CMS project.
+ *
+ * It is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License, either version 2
+ * of the License, or any later version.
+ *
+ * For the full copyright and license information, please read the
+ * LICENSE.txt file that was distributed with this source code.
+ *
+ * The TYPO3 project - inspiring people to share!
+ */
+
+use Prophecy\Argument;
+use TYPO3\CMS\Backend\Form\Element\GroupElement;
+use TYPO3\CMS\Backend\Form\NodeFactory;
+use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
+use TYPO3\CMS\Core\Tests\UnitTestCase;
+use TYPO3\CMS\Lang\LanguageService;
+
+/**
+ * Test case
+ */
+class GroupElementTest extends UnitTestCase
+{
+    /**
+     * @test
+     */
+    public function renderThrowsExceptionIfDbRecordsDoNotContainTableName()
+    {
+        $data = [
+            'parameterArray' => [
+                'fieldConf' => [
+                    'config' => [
+                        'allowed' => 'aForeignTable',
+                        'internal_type' => 'db',
+                        'show_thumbs' => true,
+                    ],
+                ],
+                // This should trigger the exception, a correct value would be 'aForeignTable_42|aLabel'
+                'itemFormElValue' => 42
+            ],
+        ];
+
+        $languageService = $this->prophesize(LanguageService::class);
+        $GLOBALS['LANG'] = $languageService->reveal();
+        $languageService->sL(Argument::cetera())->willReturnArgument(0);
+        $backendUserAuthentication = $this->prophesize(BackendUserAuthentication::class);
+        $GLOBALS['BE_USER'] = $backendUserAuthentication->reveal();
+        $backendUserAuthentication->getPagePermsClause(1)->willReturn(1);
+
+        $nodeFactoryProphecy = $this->prophesize(NodeFactory::class);
+        $subject = new GroupElement($nodeFactoryProphecy->reveal(), $data);
+
+        $this->expectException(\RuntimeException::class);
+        $this->expectExceptionCode(1468149217);
+
+        $subject->render();
+    }
+}