From c008616da3d52a7a8069c0131737a60e6f199e7a Mon Sep 17 00:00:00 2001
From: Benjamin Franzke <bfr@qbus.de>
Date: Tue, 7 Feb 2023 08:25:53 +0100
Subject: [PATCH] [TASK] Improve comments and readability in
 PageArgumentValidator
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Make clear that the early-bail out for empty pageArguments is
done to prevent setting `disableCaches` to `true`.

Also makes that that the $pageNotFoundOnCacheHashError
condition is really tied to pageArguments being non-empty.
Prevents us from refactoring that code and missing this bit.

Resolves: #99860
Related: #99859
Releases: main, 11.5, 10.4
Change-Id: I98ffa3dffe76a37970784979a2c4f2a9a64aa5bf
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/77752
Tested-by: Stefan Bürk <stefan@buerk.tech>
Tested-by: Nikita Hovratov <nikita.h@live.de>
Tested-by: core-ci <typo3@b13.com>
Reviewed-by: Benjamin Franzke <bfr@qbus.de>
Reviewed-by: Stefan Bürk <stefan@buerk.tech>
Reviewed-by: Nikita Hovratov <nikita.h@live.de>
Tested-by: Benjamin Franzke <bfr@qbus.de>
---
 .../Classes/Middleware/PageArgumentValidator.php      | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/typo3/sysext/frontend/Classes/Middleware/PageArgumentValidator.php b/typo3/sysext/frontend/Classes/Middleware/PageArgumentValidator.php
index 6625bbb69ea6..3ce21fffc8c2 100644
--- a/typo3/sysext/frontend/Classes/Middleware/PageArgumentValidator.php
+++ b/typo3/sysext/frontend/Classes/Middleware/PageArgumentValidator.php
@@ -207,16 +207,17 @@ class PageArgumentValidator implements MiddlewareInterface, LoggerAwareInterface
             return $this->evaluateQueryParametersWithoutCacheHash($pageArguments->getDynamicArguments(), $pageNotFoundOnCacheHashError);
         }
         $relevantParameters = $this->getRelevantParametersForCacheHashCalculation($pageArguments);
+        // There are parameters that would be needed for the current page, but no cHash is given.
+        // Thus, a "page not found" error is thrown - as configured via "pageNotFoundOnCHashError".
+        if (!empty($relevantParameters) && $pageNotFoundOnCacheHashError) {
+            return false;
+        }
         // There are no parameters that require a cHash.
         // We end up here when the site was called with an `id` param, e.g. https://example.org/index?id=123.
+        // Avoid disabling caches in this case.
         if (empty($relevantParameters)) {
             return true;
         }
-        // There are parameters that would be needed for the current page, but no cHash is given.
-        // Thus, a "page not found" error is thrown - as configured via "pageNotFoundOnCHashError".
-        if ($pageNotFoundOnCacheHashError) {
-            return false;
-        }
         // Caching is disabled now (but no 404)
         $this->disableCache = true;
         $this->timeTracker->setTSlogMessage('No &cHash parameter was sent for given query parameters, so caching is disabled', LogLevel::ERROR);
-- 
GitLab