Skip to content

Commit

Permalink
Do not HTML entity encode in PlainTextErrorRenderer
Browse files Browse the repository at this point in the history
The PlainTextErrorRenderer should not encode exception messages as
that's not required for plain text in the same way that it is not
required for the JsonErrorRenderer.

Closes #3298
  • Loading branch information
akrabat committed May 1, 2024
1 parent 038fd57 commit 9395e43
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Slim/Error/Renderers/PlainTextErrorRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down
7 changes: 6 additions & 1 deletion tests/Error/AbstractErrorRendererTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,19 +202,24 @@ public function testXMLErrorRendererRenderHttpException()

public function testPlainTextErrorRendererFormatFragmentMethod()
{
$exception = new Exception('Oops..', 500);
$message = 'Oops.. <br>';
$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()
Expand Down

0 comments on commit 9395e43

Please sign in to comment.