Skip to content

Commit

Permalink
[BUGFIX] ImmediateResponseException needs to be relayed
Browse files Browse the repository at this point in the history
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/+/61176
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Daniel Goerz <daniel.goerz@posteo.de>
Reviewed-by: Daniel Goerz <daniel.goerz@posteo.de>
  • Loading branch information
jnugh authored and ervaude committed Jul 1, 2019
1 parent 59d2df1 commit b4c6b92
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
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;

Expand Down Expand Up @@ -54,6 +55,11 @@ public function __construct(array $configuration = [])
*/
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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}

0 comments on commit b4c6b92

Please sign in to comment.