[BUGFIX] Trigger 404 for subpage shortcuts w/o subpages 05/50805/6
authorClaus Due <claus@namelesscoder.net>
Tue, 29 Nov 2016 13:41:30 +0000 (14:41 +0100)
committerChristian Kuhn <lolli@schwarzbu.ch>
Wed, 28 Feb 2018 10:36:58 +0000 (11:36 +0100)
This patch adds a try/catch around the call in TSFE to get
page and rootline with domain and makes getPageShortcut
function set $this->pageNotFound code, then throw error.

Change-Id: Id6aae04d7b4c2a8b267b0d949c056471c3a6b01b
Releases: master
Resolves: #78831
Reviewed-on: https://review.typo3.org/50805
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Christer V <cvi@systime.dk>
Reviewed-by: Joerg Boesche <typo3@joergboesche.de>
Reviewed-by: Stefan Neufeind <typo3.neufeind@speedpartner.de>
Tested-by: Stefan Neufeind <typo3.neufeind@speedpartner.de>
Reviewed-by: Wolfgang Klinger <wolfgang@wazum.com>
Tested-by: Wolfgang Klinger <wolfgang@wazum.com>
Reviewed-by: Tobi Kretschmann <tobi@tobishome.de>
Tested-by: Tobi Kretschmann <tobi@tobishome.de>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/core/Classes/Error/Http/ShortcutTargetPageNotFoundException.php [new file with mode: 0644]
typo3/sysext/frontend/Classes/Controller/TypoScriptFrontendController.php

diff --git a/typo3/sysext/core/Classes/Error/Http/ShortcutTargetPageNotFoundException.php b/typo3/sysext/core/Classes/Error/Http/ShortcutTargetPageNotFoundException.php
new file mode 100644 (file)
index 0000000..e26713e
--- /dev/null
@@ -0,0 +1,23 @@
+<?php
+declare(strict_types = 1);
+namespace TYPO3\CMS\Core\Error\Http;
+
+/*
+ * This file is part of the TYPO3 CMS project.
+ *
+ * It is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License, either version 2
+ * of the License, or any later version.
+ *
+ * For the full copyright and license information, please read the
+ * LICENSE.txt file that was distributed with this source code.
+ *
+ * The TYPO3 project - inspiring people to share!
+ */
+
+/**
+ * Exception when a shortcut target page could not be resolved
+ */
+class ShortcutTargetPageNotFoundException extends PageNotFoundException
+{
+}
index 663cf14..c7607e8 100644 (file)
@@ -32,6 +32,7 @@ use TYPO3\CMS\Core\Database\Query\Restriction\EndTimeRestriction;
 use TYPO3\CMS\Core\Database\Query\Restriction\StartTimeRestriction;
 use TYPO3\CMS\Core\Error\Http\PageNotFoundException;
 use TYPO3\CMS\Core\Error\Http\ServiceUnavailableException;
+use TYPO3\CMS\Core\Error\Http\ShortcutTargetPageNotFoundException;
 use TYPO3\CMS\Core\Localization\LanguageService;
 use TYPO3\CMS\Core\Locking\Exception\LockAcquireWouldBlockException;
 use TYPO3\CMS\Core\Locking\LockFactory;
@@ -1327,7 +1328,11 @@ class TypoScriptFrontendController implements LoggerAwareInterface
         $timeTracker->push('fetch_the_id rootLine/', '');
         // We store the originally requested id
         $this->requestedId = $this->id;
-        $this->getPageAndRootlineWithDomain($this->domainStartPage);
+        try {
+            $this->getPageAndRootlineWithDomain($this->domainStartPage);
+        } catch (ShortcutTargetPageNotFoundException $e) {
+            $this->pageNotFound = 1;
+        }
         $timeTracker->pull();
         // @todo: in the future, the check if "pageNotFound_handling" is configured should go away, but this breaks
         // Functional tests in workspaces currently
@@ -1541,7 +1546,7 @@ class TypoScriptFrontendController implements LoggerAwareInterface
      * @param array $pageLog An array filled with previous page uids tested by the function - new page uids are evaluated against this to avoid going in circles.
      * @param bool $disableGroupCheck If true, the group check is disabled when fetching the target page (needed e.g. for menu generation)
      * @throws \RuntimeException
-     * @throws PageNotFoundException
+     * @throws ShortcutTargetPageNotFoundException
      * @return mixed Returns the page record of the page that the shortcut pointed to.
      * @access private
      * @see getPageAndRootline()
@@ -1571,7 +1576,7 @@ class TypoScriptFrontendController implements LoggerAwareInterface
                 }
                 if (empty($page)) {
                     $message = 'This page (ID ' . $thisUid . ') is of type "Shortcut" and configured to redirect to a subpage. ' . 'However, this page has no accessible subpages.';
-                    throw new PageNotFoundException($message, 1301648328);
+                    throw new ShortcutTargetPageNotFoundException($message, 1301648328);
                 }
                 break;
             case PageRepository::SHORTCUT_MODE_PARENT_PAGE:
@@ -1579,14 +1584,14 @@ class TypoScriptFrontendController implements LoggerAwareInterface
                 $page = $this->sys_page->getPage($parent['pid'], $disableGroupCheck);
                 if (empty($page)) {
                     $message = 'This page (ID ' . $thisUid . ') is of type "Shortcut" and configured to redirect to its parent page. ' . 'However, the parent page is not accessible.';
-                    throw new PageNotFoundException($message, 1301648358);
+                    throw new ShortcutTargetPageNotFoundException($message, 1301648358);
                 }
                 break;
             default:
                 $page = $this->sys_page->getPage($idArray[0], $disableGroupCheck);
                 if (empty($page)) {
                     $message = 'This page (ID ' . $thisUid . ') is of type "Shortcut" and configured to redirect to a page, which is not accessible (ID ' . $idArray[0] . ').';
-                    throw new PageNotFoundException($message, 1301648404);
+                    throw new ShortcutTargetPageNotFoundException($message, 1301648404);
                 }
         }
         // Check if short cut page was a shortcut itself, if so look up recursively: