#95882Redirect handling error in TypoScript conditions
Description
I have a Typo3 10.4.12 with some conditions in global TS templates, regarding Site language (based onlanguage or fallback languages).
When adding a Redirect in the Redirect Backend Module, and then entering the Redirect URL into a browser, I get a Typo3 Exception:
@
#1536950931 TYPO3\CMS\Core\Configuration\TypoScript\Exception\InvalidTypoScriptConditionException
Invalid expression in condition: [siteLanguage(“languageId”) == 2 || 2 in siteLanguage(“fallbackLanguageIds”)]
@
My analysis shows this:
- The RedirectHandler->process method determines that a redirect matches and tries to find the target URL. This causes TS evaluation
- The siteLanguage condition gets the site language of the request argument (cf. Typo3ConditionFunctionProvider:159: $requestWrapper = $arguments['request'];).
- However, this request has no Language, thus getSiteLanguage returns null (in fact, it has no arguments at all)
- This causes the in check to throw an exception (2 in null)
- The request in the evaluation is (indirectely) initialized in the TypoScriptFrontendController->bootFrontendController, via $request = $request ?? $GLOBALS['TYPO3_REQUEST'] ?? ServerRequestFactory::fromGlobals();
- $GLOBALS['TYPO3_REQUEST'] is not set, so a new request is created from globals. This has no arguments set, like the language
A preprocessed request is already available in the RedirectHandler, but not yet set in the $GLOBALS.
A possible solution is to set this request when a redirect matches:
// In TYPO3\CMS\Redirects\Http\Middleware\RedirectHandler->process
// [...]
// If the matched redirect is found, resolve it, and check further
if (is_array($matchedRedirect)) {
$GLOBALS['TYPO3_REQUEST'] = $request; // TODO <- ADD THIS LINE
$url = $this->redirectService->getTargetUrl($matchedRedirect, $request->getQueryParams(), $request->getAttribute('frontend.user'), $request->getUri(), $request->getAttribute('site'));
// [...]
}
// [...]
—-
Besides this exception, all TS evaluation in case of a redirect will not correctly take request conditions into consideration. I cannot evaluate what’s the impact of this