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

fix: error page does not show source files on PHP 8.3 #8399

Closed
wants to merge 2 commits into from
Closed
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
7 changes: 5 additions & 2 deletions system/Debug/BaseExceptionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,11 @@ protected static function highlightFile(string $file, int $lineNumber, int $line

$source = str_replace(["\r\n", "\r"], "\n", $source);
$source = explode("\n", highlight_string($source, true));
$source = str_replace('<br />', "\n", $source[1]);
$source = explode("\n", str_replace("\r\n", "\n", $source));

if (PHP_VERSION_ID < 80300) {
$source = str_replace('<br />', "\n", $source[1]);
$source = explode("\n", str_replace("\r\n", "\n", $source));
}

// Get just the part to show
$start = max($lineNumber - (int) round($lines / 2), 0);
Expand Down
25 changes: 25 additions & 0 deletions tests/system/Debug/ExceptionHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,4 +237,29 @@ public function testMaskSensitiveDataTraceDataKey(): void

$this->assertSame('/var/www/CodeIgniter4/app/Controllers/Home.php', $newTrace[0]['file']);
}

public function testHighlightFile(): void
{
$highlightFile = $this->getPrivateMethodInvoker($this->handler, 'highlightFile');

$output = $highlightFile(APPPATH . 'Controllers/Home.php', 9, 3);

if (PHP_VERSION_ID >= 80300) {
$expect = <<< 'HTML'
<pre><code><span class="line"><span class="number"> 8</span> </span><span style="color: #f1ce61;">{
<span class='line highlight'><span class='number'> 9</span> return view('welcome_message');
</span></span><span style="color: #c7c7c7"></span><span style="color: #f1ce61;"></span><span style="color: #869d6a"></span><span style="color: #f1ce61;"><span class="line"><span class="number">10</span> }
</span></code></pre>
HTML;
} else {
$expect = <<< 'HTML'
<pre><code><span class="line"><span class="number"> 8</span> &nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #f1ce61;">{
<span class='line highlight'><span class='number'> 9</span> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;view('welcome_message');
</span></span><span style="color: #c7c7c7"></span><span style="color: #f1ce61;"></span><span style="color: #869d6a"></span><span style="color: #f1ce61;"><span class="line"><span class="number">10</span> &nbsp;&nbsp;&nbsp;&nbsp;}
</span></code></pre>
HTML;
}

$this->assertSame($expect, $output);
}
}
Loading