Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not HTML entity encode in PlainTextErrorRenderer #3319

Merged
merged 1 commit into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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