From 95a182a7d58908fae7169cec6879fdffc675e537 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Albrecht=20K=C3=B6hnlein?= <ak@koehnlein.eu>
Date: Sun, 19 Mar 2023 21:06:31 +0100
Subject: [PATCH] [BUGFIX] Avoid PHP 8 warnings when processing the
 INTinclude-scripts
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Avoid PHP warnings when calling the method to process INTinclude
scripts when jsInline or jsFooterInline was set.

Previously, the jsInline and jsFooterInline was called after
$TSFE->INTincScript_loadJScode(), where TSFE considered
there were no *_INT objects, however, they were processed
later-on, thus no "divKey" was set and a PHP warning
was set.

Change-Id: Ie639d58a2efce10177a41042080534ce26a1a291
Resolves: #100216
Releases: main, 11.5
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/78170
Tested-by: Benni Mack <benni@typo3.org>
Reviewed-by: Oliver Klee <typo3-coding@oliverklee.de>
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Albrecht Köhnlein <ak@koehnlein.eu>
Reviewed-by: Albrecht Köhnlein <ak@koehnlein.eu>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: core-ci <typo3@b13.com>
---
 .../frontend/Classes/Http/RequestHandler.php  |  7 ++-
 .../TypoScriptFrontendControllerTest.php      | 43 +++++++++++++++++++
 2 files changed, 48 insertions(+), 2 deletions(-)

diff --git a/typo3/sysext/frontend/Classes/Http/RequestHandler.php b/typo3/sysext/frontend/Classes/Http/RequestHandler.php
index 5c2f08c0e454..6eedadcc4f7d 100644
--- a/typo3/sysext/frontend/Classes/Http/RequestHandler.php
+++ b/typo3/sysext/frontend/Classes/Http/RequestHandler.php
@@ -674,13 +674,16 @@ class RequestHandler implements RequestHandlerInterface
             $controller->cObj
         );
 
-        $controller->INTincScript_loadJSCode();
-
         // Javascript inline code
         $inlineJS = (string)$controller->cObj->cObjGet($controller->pSetup['jsInline.'] ?? null, 'jsInline.');
         // Javascript inline code for Footer
         $inlineFooterJs = (string)$controller->cObj->cObjGet($controller->pSetup['jsFooterInline.'] ?? null, 'jsFooterInline.');
         $compressJs = (bool)($controller->config['config']['compressJs'] ?? false);
+
+        // Needs to be called after call cObjGet() calls in order to get all headerData and footerData and replacements
+        // see #100216
+        $controller->INTincScript_loadJSCode();
+
         // this option is set to "external" as default
         if (($controller->config['config']['removeDefaultJS'] ?? 'external') === 'external') {
             /*
diff --git a/typo3/sysext/frontend/Tests/Functional/Controller/TypoScriptFrontendControllerTest.php b/typo3/sysext/frontend/Tests/Functional/Controller/TypoScriptFrontendControllerTest.php
index 7f25da213d03..10f137f31814 100644
--- a/typo3/sysext/frontend/Tests/Functional/Controller/TypoScriptFrontendControllerTest.php
+++ b/typo3/sysext/frontend/Tests/Functional/Controller/TypoScriptFrontendControllerTest.php
@@ -19,6 +19,7 @@ namespace TYPO3\CMS\Frontend\Tests\Functional\Controller;
 
 use TYPO3\CMS\Core\Cache\Backend\Typo3DatabaseBackend;
 use TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait;
+use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\Internal\TypoScriptInstruction;
 use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\InternalRequest;
 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
 
@@ -76,6 +77,48 @@ class TypoScriptFrontendControllerTest extends FunctionalTestCase
         self::assertStringContainsString('footerDataFromUserInt', $body);
     }
 
+    /**
+     * @test
+     */
+    public function jsIncludesWithUserIntIsRendered(): void
+    {
+        $this->importCSVDataSet(__DIR__ . '/DataSet/LiveDefaultPages.csv');
+        $this->setUpFrontendRootPage(
+            2,
+        );
+        $this->writeSiteConfiguration(
+            'test',
+            $this->buildSiteConfiguration(2, 'https://website.local/'),
+            [$this->buildDefaultLanguageConfiguration('EN', '/en/')]
+        );
+
+        $response = $this->executeFrontendSubRequest(
+            (new InternalRequest('https://website.local/en/'))
+                ->withPageId(2)
+                ->withInstructions([
+                    (new TypoScriptInstruction())
+                        ->withTypoScript([
+                            'page' => 'PAGE',
+                            'page.' => [
+                                'jsInline.' => [
+                                    '10' => 'COA_INT',
+                                    '10.' => [
+                                        '10' => 'TEXT',
+                                        '10.' => [
+                                            'value' => 'alert(yes);',
+                                        ],
+                                    ],
+                                ],
+                            ],
+                        ]),
+                ]),
+        );
+
+        $body = (string)$response->getBody();
+        self::assertStringContainsString('/*TS_inlineJSint*/
+alert(yes);', $body);
+    }
+
     /**
      * A USER_INT method for headerAndFooterMarkersAreReplacedDuringIntProcessing()
      */
-- 
GitLab