From 44fc4f5e246c00180e88f8ca1e70dca5b1d27408 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Chris=20M=C3=BCller?= <typo3@krue.ml>
Date: Fri, 30 Sep 2022 21:03:44 +0200
Subject: [PATCH] [BUGFIX] Correct "additionalParams" handling in
 PageViewHelpers

ViewHelpers f:link.page and f:uri.page in non-Extbase
context don't handle "additionalParams" correctly
since #98484, leading to a PHP warning.

Handle that argument correctly and add some tests.

Resolves: #98486
Related: #98474
Releases: main
Change-Id: Ife768faaab346893e34dc90dac432db9925a18b4
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/75926
Tested-by: core-ci <typo3@b13.com>
Tested-by: Benni Mack <benni@typo3.org>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Benni Mack <benni@typo3.org>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
---
 .../fluid/Classes/ViewHelpers/Link/PageViewHelper.php     | 3 ++-
 .../fluid/Classes/ViewHelpers/Uri/PageViewHelper.php      | 3 ++-
 .../Functional/ViewHelpers/Link/PageViewHelperTest.php    | 8 ++++++++
 .../Functional/ViewHelpers/Uri/PageViewHelperTest.php     | 8 ++++++++
 4 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/typo3/sysext/fluid/Classes/ViewHelpers/Link/PageViewHelper.php b/typo3/sysext/fluid/Classes/ViewHelpers/Link/PageViewHelper.php
index a38b767b02a5..4ff18fab00cb 100644
--- a/typo3/sysext/fluid/Classes/ViewHelpers/Link/PageViewHelper.php
+++ b/typo3/sysext/fluid/Classes/ViewHelpers/Link/PageViewHelper.php
@@ -24,6 +24,7 @@ use TYPO3\CMS\Backend\Routing\UriBuilder as BackendUriBuilder;
 use TYPO3\CMS\Core\Http\ApplicationType;
 use TYPO3\CMS\Core\Utility\ArrayUtility;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Core\Utility\HttpUtility;
 use TYPO3\CMS\Core\Utility\MathUtility;
 use TYPO3\CMS\Extbase\Mvc\RequestInterface as ExtbaseRequestInterface;
 use TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder as ExtbaseUriBuilder;
@@ -166,7 +167,7 @@ final class PageViewHelper extends AbstractTagBasedViewHelper
             $typolinkConfiguration['linkAccessRestrictedPages'] = 1;
         }
         if ($additionalParams) {
-            $typolinkConfiguration['additionalParams'] = $additionalParams;
+            $typolinkConfiguration['additionalParams'] = HttpUtility::buildQueryString($additionalParams, '&');
         }
         if ($absolute) {
             $typolinkConfiguration['forceAbsoluteUrl'] = true;
diff --git a/typo3/sysext/fluid/Classes/ViewHelpers/Uri/PageViewHelper.php b/typo3/sysext/fluid/Classes/ViewHelpers/Uri/PageViewHelper.php
index f4736d1a67a4..15e3e631bf9b 100644
--- a/typo3/sysext/fluid/Classes/ViewHelpers/Uri/PageViewHelper.php
+++ b/typo3/sysext/fluid/Classes/ViewHelpers/Uri/PageViewHelper.php
@@ -24,6 +24,7 @@ use TYPO3\CMS\Backend\Routing\UriBuilder as BackendUriBuilder;
 use TYPO3\CMS\Core\Http\ApplicationType;
 use TYPO3\CMS\Core\Utility\ArrayUtility;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Core\Utility\HttpUtility;
 use TYPO3\CMS\Core\Utility\MathUtility;
 use TYPO3\CMS\Extbase\Mvc\RequestInterface as ExtbaseRequestInterface;
 use TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder as ExtbaseUriBuilder;
@@ -189,7 +190,7 @@ final class PageViewHelper extends AbstractViewHelper
             $typolinkConfiguration['linkAccessRestrictedPages'] = 1;
         }
         if ($additionalParams) {
-            $typolinkConfiguration['additionalParams'] = $additionalParams;
+            $typolinkConfiguration['additionalParams'] = HttpUtility::buildQueryString($additionalParams, '&');
         }
         if ($absolute) {
             $typolinkConfiguration['forceAbsoluteUrl'] = true;
diff --git a/typo3/sysext/fluid/Tests/Functional/ViewHelpers/Link/PageViewHelperTest.php b/typo3/sysext/fluid/Tests/Functional/ViewHelpers/Link/PageViewHelperTest.php
index 8cb4fbffc5a7..689040e2ab5a 100644
--- a/typo3/sysext/fluid/Tests/Functional/ViewHelpers/Link/PageViewHelperTest.php
+++ b/typo3/sysext/fluid/Tests/Functional/ViewHelpers/Link/PageViewHelperTest.php
@@ -201,6 +201,14 @@ class PageViewHelperTest extends FunctionalTestCase
                 '<f:link.page pageUid="3">linkMe</f:link.page>',
                 '<a href="/dummy-1-2/dummy-1-2-3">linkMe</a>',
             ],
+            'additional parameters one level' => [
+                '<f:link.page pageUid="3" additionalParams="{tx_examples_haiku: \'foo\'}">haiku title</f:link.page>',
+                '<a href="/dummy-1-2/dummy-1-2-3?tx_examples_haiku=foo&amp;cHash=3ed8716f46e97ba37335fa4b28ce2d8a">haiku title</a>',
+            ],
+            'additional parameters two levels' => [
+                '<f:link.page pageUid="3" additionalParams="{tx_examples_haiku: {action: \'show\', haiku: 42}}">haiku title</f:link.page>',
+                '<a href="/dummy-1-2/dummy-1-2-3?tx_examples_haiku%5Baction%5D=show&amp;tx_examples_haiku%5Bhaiku%5D=42&amp;cHash=1e0eb1e54d6bacf0138a50107c6ae29a">haiku title</a>',
+            ],
         ];
     }
 
diff --git a/typo3/sysext/fluid/Tests/Functional/ViewHelpers/Uri/PageViewHelperTest.php b/typo3/sysext/fluid/Tests/Functional/ViewHelpers/Uri/PageViewHelperTest.php
index 4897213b28f9..832603e22af2 100644
--- a/typo3/sysext/fluid/Tests/Functional/ViewHelpers/Uri/PageViewHelperTest.php
+++ b/typo3/sysext/fluid/Tests/Functional/ViewHelpers/Uri/PageViewHelperTest.php
@@ -201,6 +201,14 @@ class PageViewHelperTest extends FunctionalTestCase
                 '<f:uri.page pageUid="3" />',
                 '/dummy-1-2/dummy-1-2-3',
             ],
+            'additional parameters one level' => [
+                '<f:uri.page pageUid="3" additionalParams="{tx_examples_haiku: \'foo\'}">haiku title</f:uri.page>',
+                '/dummy-1-2/dummy-1-2-3?tx_examples_haiku=foo&amp;cHash=3ed8716f46e97ba37335fa4b28ce2d8a',
+            ],
+            'additional parameters two levels' => [
+                '<f:uri.page pageUid="3" additionalParams="{tx_examples_haiku: {action: \'show\', haiku: 42}}">haiku title</f:uri.page>',
+                '/dummy-1-2/dummy-1-2-3?tx_examples_haiku%5Baction%5D=show&amp;tx_examples_haiku%5Bhaiku%5D=42&amp;cHash=1e0eb1e54d6bacf0138a50107c6ae29a',
+            ],
         ];
     }
 
-- 
GitLab