Project

General

Profile

Actions

Bug #95882

closed

Redirect handling error in TypoScript conditions

Added by Philip Masser over 2 years ago. Updated over 1 year ago.

Status:
Closed
Priority:
Should have
Assignee:
Category:
Link Handling, Site Handling & Routing
Target version:
-
Start date:
2021-11-05
Due date:
% Done:

100%

Estimated time:
TYPO3 Version:
10
PHP Version:
7.2
Tags:
Complexity:
Is Regression:
Sprint Focus:

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


Related issues 1 (0 open1 closed)

Related to TYPO3 Core - Task #92666: Use the current request to resolve TSFE in redirect resolvingClosedBenni Mack2020-10-22

Actions
Actions

Also available in: Atom PDF