[BUGFIX] ImmediateResponseException needs to be relayed 70/60370/6
authorJonas Schwabe <jonas@jnugh.de>
Thu, 4 Apr 2019 10:21:17 +0000 (12:21 +0200)
committerDaniel Goerz <daniel.goerz@posteo.de>
Mon, 1 Jul 2019 07:11:55 +0000 (09:11 +0200)
ImmediateResponseException were not handled correctly during content
object rendering when running in a production environment.
This patch makes sure that ImmediateResponses are handled as such instead
of just printing them during template rendering.

Resolves: #88080
Releases: master, 9.5
Change-Id: Id211b4064b438b3df0744c7a0de90b642ed872de
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/60370
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Benni Mack <benni@typo3.org>
Tested-by: Jonas Schwabe <jonas.schwabe@eyeworkers.de>
Tested-by: Daniel Goerz <daniel.goerz@posteo.de>
Reviewed-by: Benni Mack <benni@typo3.org>
Reviewed-by: Jonas Schwabe <jonas.schwabe@eyeworkers.de>
Reviewed-by: Daniel Goerz <daniel.goerz@posteo.de>
typo3/sysext/frontend/Classes/ContentObject/Exception/ProductionExceptionHandler.php
typo3/sysext/frontend/Tests/Unit/ContentObject/Exception/ProductionExceptionHandlerTest.php [new file with mode: 0644]

index b9d5c3a..ac261da 100644 (file)
@@ -17,6 +17,7 @@ namespace TYPO3\CMS\Frontend\ContentObject\Exception;
 use Psr\Log\LoggerAwareInterface;
 use Psr\Log\LoggerAwareTrait;
 use TYPO3\CMS\Core\Crypto\Random;
+use TYPO3\CMS\Core\Http\ImmediateResponseException;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Frontend\ContentObject\AbstractContentObject;
 
@@ -54,6 +55,11 @@ class ProductionExceptionHandler implements ExceptionHandlerInterface, LoggerAwa
      */
     public function handle(\Exception $exception, AbstractContentObject $contentObject = null, $contentObjectConfiguration = [])
     {
+        // ImmediateResponseException should work similar to exit / die and must therefore not be handled by this ExceptionHandler.
+        if ($exception instanceof ImmediateResponseException) {
+            throw $exception;
+        }
+
         if (!empty($this->configuration['ignoreCodes.'])) {
             if (in_array($exception->getCode(), array_map('intval', $this->configuration['ignoreCodes.']), true)) {
                 throw $exception;
diff --git a/typo3/sysext/frontend/Tests/Unit/ContentObject/Exception/ProductionExceptionHandlerTest.php b/typo3/sysext/frontend/Tests/Unit/ContentObject/Exception/ProductionExceptionHandlerTest.php
new file mode 100644 (file)
index 0000000..bc7bb89
--- /dev/null
@@ -0,0 +1,56 @@
+<?php
+declare(strict_types = 1);
+
+namespace TYPO3\CMS\Frontend\Tests\Unit\ContentObject\Exception;
+
+/*
+ * 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!
+ */
+
+use Psr\Log\NullLogger;
+use TYPO3\CMS\Core\Http\HtmlResponse;
+use TYPO3\CMS\Core\Http\ImmediateResponseException;
+use TYPO3\CMS\Frontend\ContentObject\Exception\ProductionExceptionHandler;
+use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
+
+/**
+ * Test case
+ */
+class ProductionExceptionHandlerTest extends UnitTestCase
+{
+    /**
+     * @var ProductionExceptionHandler
+     */
+    protected $subject;
+
+    /**
+     * Sets up this test case.
+     */
+    protected function setUp(): void
+    {
+        $this->subject = new ProductionExceptionHandler();
+        $this->subject->setLogger(new NullLogger());
+    }
+    /**
+     * @test
+     */
+    public function relayImmediateResponseException()
+    {
+        $response = $this->getMockBuilder(HtmlResponse::class)
+            ->disableOriginalConstructor()
+            ->getMock();
+        $exception = new ImmediateResponseException($response, 1533939251);
+
+        $this->expectException(ImmediateResponseException::class);
+        $this->subject->handle($exception);
+    }
+}