From 2d982b0f32311b942c763463edc001acc93ba71c Mon Sep 17 00:00:00 2001 From: Ilia Alshanetsky Date: Sun, 23 Aug 2026 13:39:24 -0400 Subject: [PATCH 1/2] Use consistent HTML escaping in error details fragment The exception message and trace in renderExceptionFragment() used bare htmlentities(), whose default flags differ across PHP versions and inherit the default_charset ini, while the title and description are escaped with explicit ENT_QUOTES | ENT_SUBSTITUTE flags and a pinned UTF-8 charset. Align the fragment escaping with the same explicit call so behavior is identical on every supported PHP version. --- Slim/Error/Renderers/HtmlErrorRenderer.php | 11 ++++++++--- tests/Error/AbstractErrorRendererTest.php | 17 +++++++++++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/Slim/Error/Renderers/HtmlErrorRenderer.php b/Slim/Error/Renderers/HtmlErrorRenderer.php index 58f5b5630..75af44837 100644 --- a/Slim/Error/Renderers/HtmlErrorRenderer.php +++ b/Slim/Error/Renderers/HtmlErrorRenderer.php @@ -14,7 +14,6 @@ use Throwable; use function get_class; -use function htmlentities; use function htmlspecialchars; use function sprintf; @@ -51,14 +50,20 @@ private function renderExceptionFragment(Throwable $exception): string $code = $exception->getCode(); $html .= sprintf('
Code: %s
', $code); - $html .= sprintf('
Message: %s
', htmlentities($exception->getMessage())); + $html .= sprintf( + '
Message: %s
', + htmlspecialchars($exception->getMessage(), ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8') + ); $html .= sprintf('
File: %s
', $exception->getFile()); $html .= sprintf('
Line: %s
', $exception->getLine()); $html .= '

Trace

'; - $html .= sprintf('
%s
', htmlentities($exception->getTraceAsString())); + $html .= sprintf( + '
%s
', + htmlspecialchars($exception->getTraceAsString(), ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8') + ); return $html; } diff --git a/tests/Error/AbstractErrorRendererTest.php b/tests/Error/AbstractErrorRendererTest.php index f47fee4c8..e71d2b259 100644 --- a/tests/Error/AbstractErrorRendererTest.php +++ b/tests/Error/AbstractErrorRendererTest.php @@ -74,6 +74,23 @@ public function testHTMLErrorRendererRenderFragmentMethod() $this->assertMatchesRegularExpression('/.*Line*/', $output); } + public function testHTMLErrorRendererEscapesQuotesInErrorDetails() + { + $exception = new Exception("O'Brien