diff --git a/Slim/Error/Renderers/PlainTextErrorRenderer.php b/Slim/Error/Renderers/PlainTextErrorRenderer.php index 3d80c74be..9788568d5 100644 --- a/Slim/Error/Renderers/PlainTextErrorRenderer.php +++ b/Slim/Error/Renderers/PlainTextErrorRenderer.php @@ -46,7 +46,7 @@ private function formatExceptionFragment(Throwable $exception): string /** @var int|string $code */ $text .= sprintf("Code: %s\n", $code); - $text .= sprintf("Message: %s\n", htmlentities($exception->getMessage())); + $text .= sprintf("Message: %s\n", $exception->getMessage()); $text .= sprintf("File: %s\n", $exception->getFile()); diff --git a/tests/Error/AbstractErrorRendererTest.php b/tests/Error/AbstractErrorRendererTest.php index 13639dce3..88cfa135b 100644 --- a/tests/Error/AbstractErrorRendererTest.php +++ b/tests/Error/AbstractErrorRendererTest.php @@ -202,19 +202,24 @@ public function testXMLErrorRendererRenderHttpException() public function testPlainTextErrorRendererFormatFragmentMethod() { - $exception = new Exception('Oops..', 500); + $message = 'Oops..
'; + $exception = new Exception($message, 500); $renderer = new PlainTextErrorRenderer(); $reflectionRenderer = new ReflectionClass(PlainTextErrorRenderer::class); $method = $reflectionRenderer->getMethod('formatExceptionFragment'); $method->setAccessible(true); $output = $method->invoke($renderer, $exception); + $this->assertIsString($output); $this->assertMatchesRegularExpression('/.*Type:*/', $output); $this->assertMatchesRegularExpression('/.*Code:*/', $output); $this->assertMatchesRegularExpression('/.*Message*/', $output); $this->assertMatchesRegularExpression('/.*File*/', $output); $this->assertMatchesRegularExpression('/.*Line*/', $output); + + // ensure the renderer doesn't reformat the message + $this->assertMatchesRegularExpression("/.*$message/", $output); } public function testPlainTextErrorRendererDisplaysErrorDetails()