Skip to content

Commit ad92887

Browse files
authored
Merge pull request #3319 from akrabat/3298-do-not-encode-plain-text-errors
Do not HTML entity encode in PlainTextErrorRenderer
2 parents 038fd57 + 9395e43 commit ad92887

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

Slim/Error/Renderers/PlainTextErrorRenderer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ private function formatExceptionFragment(Throwable $exception): string
4646
/** @var int|string $code */
4747
$text .= sprintf("Code: %s\n", $code);
4848

49-
$text .= sprintf("Message: %s\n", htmlentities($exception->getMessage()));
49+
$text .= sprintf("Message: %s\n", $exception->getMessage());
5050

5151
$text .= sprintf("File: %s\n", $exception->getFile());
5252

tests/Error/AbstractErrorRendererTest.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,19 +202,24 @@ public function testXMLErrorRendererRenderHttpException()
202202

203203
public function testPlainTextErrorRendererFormatFragmentMethod()
204204
{
205-
$exception = new Exception('Oops..', 500);
205+
$message = 'Oops.. <br>';
206+
$exception = new Exception($message, 500);
206207
$renderer = new PlainTextErrorRenderer();
207208
$reflectionRenderer = new ReflectionClass(PlainTextErrorRenderer::class);
208209

209210
$method = $reflectionRenderer->getMethod('formatExceptionFragment');
210211
$method->setAccessible(true);
211212
$output = $method->invoke($renderer, $exception);
213+
$this->assertIsString($output);
212214

213215
$this->assertMatchesRegularExpression('/.*Type:*/', $output);
214216
$this->assertMatchesRegularExpression('/.*Code:*/', $output);
215217
$this->assertMatchesRegularExpression('/.*Message*/', $output);
216218
$this->assertMatchesRegularExpression('/.*File*/', $output);
217219
$this->assertMatchesRegularExpression('/.*Line*/', $output);
220+
221+
// ensure the renderer doesn't reformat the message
222+
$this->assertMatchesRegularExpression("/.*$message/", $output);
218223
}
219224

220225
public function testPlainTextErrorRendererDisplaysErrorDetails()

0 commit comments

Comments
 (0)