Skip to content

Commit

Permalink
Merge pull request #3319 from akrabat/3298-do-not-encode-plain-text-e…
Browse files Browse the repository at this point in the history
…rrors

Do not HTML entity encode in PlainTextErrorRenderer
  • Loading branch information
akrabat committed May 9, 2024
2 parents 038fd57 + 9395e43 commit ad92887
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 ad92887

Please sign in to comment.