From 3db6d6bd20bd8b8d9cc1494c3c7e8c001a734b62 Mon Sep 17 00:00:00 2001 From: David Steeb Date: Wed, 23 Sep 2026 23:27:05 +0200 Subject: [PATCH 1/2] [BUGFIX] Treat a null code language as autodetect code_language is a nullable column, so a record can hold NULL where the TCA default would have written an empty string. "??" substitutes only for NULL, so the falsy check read that NULL as "a language was chosen" and passed it to the highlighter. There it ends the request: on PHP 8.4 highlight() throws DomainException: Unknown language: "", and on 8.5 the lookup trips "Using null as an array offset" first, which TYPO3 turns into an exception. Either way the page returns a 500. Normalise the value to a string before deciding, so NULL takes the autodetect branch like an empty string does. --- Classes/DataProcessing/HighlightProcessor.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Classes/DataProcessing/HighlightProcessor.php b/Classes/DataProcessing/HighlightProcessor.php index b88292e..9a7c63b 100644 --- a/Classes/DataProcessing/HighlightProcessor.php +++ b/Classes/DataProcessing/HighlightProcessor.php @@ -46,13 +46,18 @@ public function process(ContentObjectRenderer $cObj, array $contentObjectConfigu $targetVariableName = $cObj->stdWrapValue('as', $processorConfiguration, 'bodytext_formatted'); $highlight = GeneralUtility::makeInstance(Highlighter::class); + // The column is nullable, so a record can carry NULL rather than the empty + // string the TCA default writes. Normalise before deciding, because "??" + // only substitutes for NULL and would send it on to the highlighter. + $language = trim((string)($processedData['data']['code_language'] ?? '')); + // Let highlight.php decide which code language to use from all registered if "detect automatically" is selected. - if (!($processedData['data']['code_language'] ?? true)) { + if ($language === '') { $languages = $highlight->listLanguages(); $highlight->setAutodetectLanguages($languages); $highlighted = $highlight->highlightAuto($processedData['data'][$fieldName]); } else { - $highlighted = $highlight->highlight($processedData['data']['code_language'], $processedData['data'][$fieldName]); + $highlighted = $highlight->highlight($language, $processedData['data'][$fieldName]); } $processedData[$targetVariableName]['code'] = $highlighted->value; From 354238853c8b6932ad6cc65a46b1197c2677fd38 Mon Sep 17 00:00:00 2001 From: David Steeb Date: Thu, 24 Sep 2026 07:34:38 +0200 Subject: [PATCH 2/2] [BUGFIX] Fall back to autodetect on unknown language highlight() throws DomainException when the given language is not registered, and nothing caught it, so a stored value that no longer resolves ended the request with a 500 - the same failure as a null language, just from the other direction. A language can stop resolving without the record changing: it may be dropped from the registered set, or the record may arrive from an installation that had it. Catch that one exception and detect the language instead. A language that does resolve is still used as it was. --- Classes/DataProcessing/HighlightProcessor.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/Classes/DataProcessing/HighlightProcessor.php b/Classes/DataProcessing/HighlightProcessor.php index 9a7c63b..82733fb 100644 --- a/Classes/DataProcessing/HighlightProcessor.php +++ b/Classes/DataProcessing/HighlightProcessor.php @@ -51,13 +51,23 @@ public function process(ContentObjectRenderer $cObj, array $contentObjectConfigu // only substitutes for NULL and would send it on to the highlighter. $language = trim((string)($processedData['data']['code_language'] ?? '')); + $highlighted = null; + if ($language !== '') { + try { + $highlighted = $highlight->highlight($language, $processedData['data'][$fieldName]); + } catch (\DomainException $e) { + // The stored language is not registered - it may have been dropped from + // the list, or the record may come from an installation that had it. + // Detect instead, so a stale value does not take the page down. + $highlighted = null; + } + } + // Let highlight.php decide which code language to use from all registered if "detect automatically" is selected. - if ($language === '') { + if ($highlighted === null) { $languages = $highlight->listLanguages(); $highlight->setAutodetectLanguages($languages); $highlighted = $highlight->highlightAuto($processedData['data'][$fieldName]); - } else { - $highlighted = $highlight->highlight($language, $processedData['data'][$fieldName]); } $processedData[$targetVariableName]['code'] = $highlighted->value;