[BUGFIX] Do not add category to empty table names 38/20938/5
authorAlexander Opitz <opitz.alexander@googlemail.com>
Tue, 21 May 2013 07:42:34 +0000 (09:42 +0200)
committerWouter Wolters <typo3@wouterwolters.nl>
Wed, 12 Jun 2013 18:07:13 +0000 (20:07 +0200)
If the $GLOBALS['TYPO3_CONF_VARS']['SYS']['defaultCategorizedTables']
is empty or you have empty strings between commas then we try to add
empty tablenames to the table definitions.

This is fixed by setting removeEmptyValues to true in trimExplode
and adding a RuntimeException to the add function to prevent
others (extensions) breaking the functionality.

Resolves: #48381
Releases: 6.2, 6.1
Change-Id: I4a8d43a0ff75da298ace4f1d33a5dcf2d2ac569f
Reviewed-on: https://review.typo3.org/20938
Reviewed-by: Wouter Wolters
Tested-by: Wouter Wolters
Reviewed-by: Peter Niederlag
Tested-by: Peter Niederlag
typo3/sysext/core/Classes/Category/CategoryRegistry.php
typo3/sysext/core/Tests/Unit/Category/CategoryRegistryTest.php

index d710e2f..ef65b3a 100644 (file)
@@ -72,10 +72,15 @@ class CategoryRegistry implements \TYPO3\CMS\Core\SingletonInterface {
         *              + position: insert position of the categories field
         *              + fieldConfiguration: TCA field config array to override defaults
         * @return bool
+        * @throws \RuntimeException
         */
        public function add($extensionKey, $tableName, $fieldName = 'categories', $options = array()) {
                $result = FALSE;
 
+               if ($tableName === '') {
+                       throw new \RuntimeException('TYPO3\\CMS\\Core\\Category\\CategoryRegistry No tableName given.', 1369122038);
+               }
+
                        // Makes sure there is an existing table configuration and nothing registered yet:
                if (!$this->isRegistered($tableName, $fieldName)) {
                        $this->registry[$extensionKey][$tableName] = array (
@@ -192,8 +197,11 @@ class CategoryRegistry implements \TYPO3\CMS\Core\SingletonInterface {
         * @return void
         */
        protected function registerDefaultCategorizedTables() {
-
-               $defaultCategorizedTables = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $GLOBALS['TYPO3_CONF_VARS']['SYS']['defaultCategorizedTables']);
+               $defaultCategorizedTables = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(
+                       ',',
+                       $GLOBALS['TYPO3_CONF_VARS']['SYS']['defaultCategorizedTables'],
+                       TRUE
+               );
                foreach ($defaultCategorizedTables as $defaultCategorizedTable) {
                        if (!$this->isRegistered($defaultCategorizedTable)) {
                                $this->add('core', $defaultCategorizedTable, 'categories');
index 0f248ee..08a6423 100644 (file)
@@ -91,6 +91,15 @@ class CategoryRegistryTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
 
        /**
         * @test
+        * @expectedException \RuntimeException
+        * @expectedExceptionCode 1369122038
+        */
+       public function doesAddThrowExceptionOnEmptyAdds() {
+               $this->fixture->add('test_extension_a', '', 'categories');
+       }
+
+       /**
+        * @test
         */
        public function areMultipleElementsOfSameExtensionRegistered() {
                $this->fixture->add('test_extension_a', $this->tables['first'], 'categories');
@@ -176,7 +185,7 @@ class CategoryRegistryTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
        /**
         * @test
         */
-       public function areDefaultCategorizedTabledLoaded() {
+       public function areDefaultCategorizedTablesLoaded() {
                $GLOBALS['TYPO3_CONF_VARS']['SYS']['defaultCategorizedTables'] = $this->tables['first'] . ',' . $this->tables['second'];
                $this->fixture->applyTca();
 
@@ -188,6 +197,28 @@ class CategoryRegistryTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
        /**
         * @test
         */
+       public function areEmptyStringDefaultCategorizedTablesLoaded() {
+               $GLOBALS['TYPO3_CONF_VARS']['SYS']['defaultCategorizedTables'] = '';
+               $this->fixture->applyTca();
+
+               $registry = $this->fixture->get();
+               $this->assertNull($registry['core']);
+       }
+
+       /**
+        * @test
+        */
+       public function areNullDefaultCategorizedTablesLoaded() {
+               $GLOBALS['TYPO3_CONF_VARS']['SYS']['defaultCategorizedTables'] = NULL;
+               $this->fixture->applyTca();
+
+               $registry = $this->fixture->get();
+               $this->assertNull($registry['core']);
+       }
+
+       /**
+        * @test
+        */
        public function canApplyTca() {
                $this->fixture->add('test_extension_a', $this->tables['first'], 'categories');
                $this->fixture->add('test_extension_b', $this->tables['second'], 'categories');