[BUGFIX] Handle null values correctly to avoid PHP errors 97/64997/4
authorstiffes <johannes.schlier@b13.com>
Mon, 6 Jul 2020 10:07:08 +0000 (12:07 +0200)
committerBenni Mack <benni@typo3.org>
Tue, 7 Jul 2020 09:11:10 +0000 (11:11 +0200)
The new RteHtmlParser->transformTextForPersistence() method
expects a string value. Before this patch the given value
was simply passed without checking its type or casting it.

However, if "null" is handed in (by e.g. a translated record which
expects null), null is now kept.

Resolves: #91749
Releases: master, 10.4
Change-Id: I9db872ca73dcf2bbfc2ac2d0b67d45ca3ffd4c5e

typo3/sysext/core/Classes/DataHandling/DataHandler.php
typo3/sysext/core/Tests/Functional/DataHandling/DataHandler/DefaultValuesTest.php

index 9273ab5..9221ffb 100644 (file)
@@ -1759,12 +1759,16 @@ class DataHandler implements LoggerAwareInterface
         if ($this->dontProcessTransformations) {
             return $valueArray;
         }
+        // Keep null as value
+        if ($value === null) {
+            return $valueArray;
+        }
         if (isset($tcaFieldConf['enableRichtext']) && (bool)$tcaFieldConf['enableRichtext'] === true) {
             $recordType = BackendUtility::getTCAtypeValue($table, $this->checkValue_currentRecord);
             $richtextConfigurationProvider = GeneralUtility::makeInstance(Richtext::class);
             $richtextConfiguration = $richtextConfigurationProvider->getConfiguration($table, $field, $realPid, $recordType, $tcaFieldConf);
             $rteParser = GeneralUtility::makeInstance(RteHtmlParser::class);
-            $valueArray['value'] = $rteParser->transformTextForPersistence($value, $richtextConfiguration['proc.'] ?? []);
+            $valueArray['value'] = $rteParser->transformTextForPersistence((string)$value, $richtextConfiguration['proc.'] ?? []);
         }
 
         return $valueArray;
index ffcc406..7ca6b49 100644 (file)
@@ -145,4 +145,23 @@ TCAdefaults.tt_content.header = local space
         $newContentRecord = BackendUtility::getRecord('tt_content', $newContentId);
         self::assertEquals($newContentRecord['header'], 'local space');
     }
+
+    /**
+     * @test
+     */
+    public function defaultValueForNullTextfieldsIsConsidered(): void
+    {
+        // New content element without bodytext
+        $GLOBALS['TCA']['tt_content']['columns']['bodytext']['l10n_mode'] = 'exclude';
+        $GLOBALS['TCA']['tt_content']['columns']['bodytext']['config']['enableRichtext'] = true;
+        $map = $this->actionService->createNewRecord('tt_content', self::PAGE_DATAHANDLER, [
+            'header' => 'Random header',
+            'bodytext' => null
+        ]);
+        $newContentId = reset($map['tt_content']);
+        $map = $this->actionService->localizeRecord('tt_content', $newContentId, 1);
+        $translatedContentId = reset($map['tt_content']);
+        $newContentRecord = BackendUtility::getRecord('tt_content', $translatedContentId);
+        self::assertNull($newContentRecord['bodytext']);
+    }
 }