10000 bug #57355 [ErrorHandler] Fix rendered exception code highlighting on… · symfony/symfony@f2d95c4 · GitHub
[go: up one dir, main page]

Skip to content

Commit f2d95c4

Browse files
committed
bug #57355 [ErrorHandler] Fix rendered exception code highlighting on PHP 8.3 (tscni)
This PR was merged into the 5.4 branch. Discussion ---------- [ErrorHandler] Fix rendered exception code highlighting on PHP 8.3 | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | Fix #57354 | License | MIT #51586 made some mistakes when fixing the use of `highlight_file()` for PHP 8.3: - It assumed that the inner `<span>` were changed to `<code>` - It did not properly adjust the pattern for `\n` when splitting the highlighting across multiple lines - It replaced all spaces with `&nbsp`, including those inside tags, breaking the highlighting entirely The first two are easy to fix. The latter one not so much without CSS adjustments. But just changing `white-space: nowrap` to `white-space: pre` would remove the need for that. I'm a bit worried about side effects though and I'm not sure if `CodeExtension` uses separate styling somewhere, but I can't find anything problematic at least. A test would be a bit cumbersome to add for this, so unless very much preferred I'd rather not spend the time on it. But at least in manual tests this resolved all the highlighting issues. Commits ------- 2b46e2a [ErrorHandler] Fix rendered exception code highlighting on PHP 8.3
2 parents 5036d0f + 2b46e2a commit f2d95c4

File tree

3 files changed

+7
-11
lines changed

3 files changed

+7
-11
lines changed

src/Symfony/Bridge/Twig/Extension/CodeExtension.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,10 @@ public function fileExcerpt(string $file, int $line, int $srcContext = 3): ?stri
129129
if (\PHP_VERSION_ID >= 80300) {
130130
// remove main pre/code tags
131131
$code = preg_replace('#^<pre.*?>\s*<code.*?>(.*)</code>\s*</pre>#s', '\\1', $code);
132-
// split multiline code tags
133-
$code = preg_replace_callback('#<code ([^>]++)>((?:[^<]*+\\n)++[^<]*+)</code>#', function ($m) {
134-
return "<code $m[1]>".str_replace("\n", "</code>\n<code $m[1]>", $m[2]).'</code>';
132+
// split multiline span tags
133+
$code = preg_replace_callback('#<span ([^>]++)>((?:[^<\\n]*+\\n)++[^<]*+)</span>#', function ($m) {
134+
return "<span $m[1]>".str_replace("\n", "</span>\n<span $m[1]>", $m[2]).'</span>';
135135
}, $code);
136-
// Convert spaces to html entities to preserve indentation when rendered
137-
$code = str_replace(' ', '&nbsp;', $code);
138136
$cont 10000 ent = explode("\n", $code);
139137
} else {
140138
// remove main code/span tags

src/Symfony/Component/ErrorHandler/ErrorRenderer/HtmlErrorRenderer.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -274,12 +274,10 @@ private function fileExcerpt(string $file, int $line, int $srcContext = 3): stri
274274
if (\PHP_VERSION_ID >= 80300) {
275275
// remove main pre/code tags
276276
$code = preg_replace('#^<pre.*?>\s*<code.*?>(.*)</code>\s*</pre>#s', '\\1', $code);
277-
// split multiline code tags
278-
$code = preg_replace_callback('#<code ([^>]++)>((?:[^<]*+\\n)++[^<]*+)</code>#', function ($m) {
279-
return "<code $m[1]>".str_replace("\n", "</code>\n<code $m[1]>", $m[2]).'</code>';
277+
// split multiline span tags
278+
$code = preg_replace_callback('#<span ([^>]++)>((?:[^<\\n]*+\\n)++[^<]*+)</span>#', function ($m) {
279+
return "<span $m[1]>".str_replace("\n", "</span>\n<span $m[1]>", $m[2]).'</span>';
280280
}, $code);
281-
// Convert spaces to html entities to preserve indentation when rendered
282-
$code = str_replace(' ', '&nbsp;', $code);
283281
$content = explode("\n", $code);
284282
} else {
285283
// remove main code/span tags

src/Symfony/Component/ErrorHandler/Resources/assets/css/exception.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ header .container { display: flex; justify-content: space-between; }
242242
.trace-code li { color: #969896; margin: 0; padding-left: 10px; float: left; width: 100%; }
243243
.trace-code li + li { margin-top: 5px; }
244244
.trace-code li.selected { background: var(--trace-selected-background); margin-top: 2px; }
245-
.trace-code li code { color: var(--base-6); white-space: nowrap; }
245+
.trace-code li code { color: var(--base-6); white-space: pre; }
246246

247247
.trace-as-text .stacktrace { line-height: 1.8; margin: 0 0 15px; white-space: pre-wrap; }
248248

0 commit comments

Comments
 (0)
0