From e21e9b44cd6ea338914f09dde0512152af020ba1 Mon Sep 17 00:00:00 2001 From: Oliver Klee Date: Sun, 10 Sep 2023 14:05:03 +0200 Subject: [PATCH] [BUGFIX] Do not try to parse non-strings as XML in DataHandler MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If the flexforms data is null, there is no point trying to parse that as XML. This avoids type errors when `GeneralUtility` gets native parameter type declarations for `GU::xml2array`, and it should also slightly increase performance. Also fix the corresponding PHPDoc type annotation to reflect that a parameter in reality needs to be nullable. Resolves: #101891 Releases: main, 12.4, 11.5 Change-Id: I39efc1d26300634c0bed74aee1f7ebd444acb8c0 Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/81058 Tested-by: core-ci Reviewed-by: Stefan Bürk Tested-by: Stefan Bürk --- .../sysext/core/Classes/DataHandling/DataHandler.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/typo3/sysext/core/Classes/DataHandling/DataHandler.php b/typo3/sysext/core/Classes/DataHandling/DataHandler.php index da1d3ccb14db..35cc23076fbb 100644 --- a/typo3/sysext/core/Classes/DataHandling/DataHandler.php +++ b/typo3/sysext/core/Classes/DataHandling/DataHandler.php @@ -4096,13 +4096,13 @@ public function insertNewCopyVersion($table, $fieldArray, $realPid) * @param string $table Table name * @param int $uid Record uid * @param string $field Field name being processed - * @param string $value Input value to be processed. + * @param string|null $value Input value to be processed. * @param array $row Record array * @param array $conf TCA field configuration * @param int $realDestPid Real page id (pid) the record is copied to * @param int $language Language ID used in the duplicated record * @param array $workspaceOptions Options to be forwarded if actions happen on a workspace currently - * @return array|string + * @return array|string|null * @internal * @see copyRecord() */ @@ -4127,12 +4127,12 @@ public function copyRecord_procBasedOnFieldType($table, $uid, $field, $value, $r $row ); $dataStructureArray = $flexFormTools->parseDataStructureByIdentifier($dataStructureIdentifier); - $currentValueArray = GeneralUtility::xml2array($value); + $currentValue = is_string($value) ? GeneralUtility::xml2array($value) : null; // Traversing the XML structure, processing files: - if (is_array($currentValueArray)) { - $currentValueArray['data'] = $this->checkValue_flex_procInData($currentValueArray['data'], [], $dataStructureArray, [$table, $uid, $field, $realDestPid], 'copyRecord_flexFormCallBack', $workspaceOptions); + if (is_array($currentValue)) { + $currentValue['data'] = $this->checkValue_flex_procInData($currentValue['data'], [], $dataStructureArray, [$table, $uid, $field, $realDestPid], 'copyRecord_flexFormCallBack', $workspaceOptions); // Setting value as an array! -> which means the input will be processed according to the 'flex' type when the new copy is created. - $value = $currentValueArray; + $value = $currentValue; } } return $value;