From a19c3e8ba2c16d66554cb2db3cdc9b87385e47d2 Mon Sep 17 00:00:00 2001 From: Oliver Klee <typo3-coding@oliverklee.de> 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/+/81059 Reviewed-by: Stefan Bürk <stefan@buerk.tech> Tested-by: core-ci <typo3@b13.com> Tested-by: Stefan Bürk <stefan@buerk.tech> --- .../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 15b1f73320ee..0e5262ef9498 100644 --- a/typo3/sysext/core/Classes/DataHandling/DataHandler.php +++ b/typo3/sysext/core/Classes/DataHandling/DataHandler.php @@ -3722,13 +3722,13 @@ class DataHandler implements LoggerAwareInterface * @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 (from sys_language table) 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() */ @@ -3753,12 +3753,12 @@ class DataHandler implements LoggerAwareInterface $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; -- GitLab