[BUGFIX] Ensure PageRouter only operates with previous result 74/60474/2
authorBenni Mack <benni@typo3.org>
Mon, 15 Apr 2019 04:52:49 +0000 (06:52 +0200)
committerSusanne Moog <look@susi.dev>
Wed, 17 Apr 2019 09:08:48 +0000 (11:08 +0200)
If no previous result given, an exception should be thrown,
instead of a PHP error.

Resolves: #88133
Releases: master, 9.5
Change-Id: I708e735e664589b0fc8d125a60b9970128b584af
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/60474
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Dmitry Dulepov
Tested-by: Susanne Moog <look@susi.dev>
Reviewed-by: Dmitry Dulepov
Reviewed-by: Susanne Moog <look@susi.dev>
typo3/sysext/core/Classes/Routing/PageRouter.php
typo3/sysext/core/Tests/Unit/Routing/PageRouterTest.php

index ac477b0..b0a2112 100644 (file)
@@ -113,6 +113,9 @@ class PageRouter implements RouterInterface
      */
     public function matchRequest(ServerRequestInterface $request, RouteResultInterface $previousResult = null): RouteResultInterface
     {
+        if (!($previousResult instanceof RouteResultInterface)) {
+            throw new RouteNotFoundException('No previous result given. Cannot find a page for an empty route part', 1555303496);
+        }
         $urlPath = $previousResult->getTail();
         $prefixedUrlPath = '/' . trim($urlPath, '/');
         $slugCandidates = $this->getCandidateSlugsFromRoutePath($urlPath ?: '/');
index 7e76484..3d2f56a 100644 (file)
@@ -19,6 +19,7 @@ namespace TYPO3\CMS\Core\Tests\Unit\Routing;
 use TYPO3\CMS\Core\Http\ServerRequest;
 use TYPO3\CMS\Core\Routing\PageArguments;
 use TYPO3\CMS\Core\Routing\PageRouter;
+use TYPO3\CMS\Core\Routing\RouteNotFoundException;
 use TYPO3\CMS\Core\Routing\SiteRouteResult;
 use TYPO3\CMS\Core\Site\Entity\Site;
 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
@@ -33,6 +34,19 @@ class PageRouterTest extends UnitTestCase
     /**
      * @test
      */
+    public function matchRequestThrowsExceptionIfNoPreviousResultGiven()
+    {
+        $this->expectException(RouteNotFoundException::class);
+        $this->expectExceptionCode(1555303496);
+        $incomingUrl = 'https://king.com/lotus-flower/en/mr-magpie/bloom';
+        $request = new ServerRequest($incomingUrl, 'GET');
+        $subject = new PageRouter(new Site('lotus-flower', 13, []));
+        $subject->matchRequest($request, null);
+    }
+
+    /**
+     * @test
+     */
     public function properSiteConfigurationFindsRoute()
     {
         $incomingUrl = 'https://king.com/lotus-flower/en/mr-magpie/bloom';