Skip to content

Commit 620f90d

Browse files
lyrixxnicolas-grekas
authored andcommitted
[Debug] Fixed the formatPath when a custom fileLinkFormat is defined
1 parent 6df7d05 commit 620f90d

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

src/Symfony/Component/Debug/ExceptionHandler.php

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function __construct($debug = true, $charset = null, $fileLinkFormat = nu
4040
{
4141
$this->debug = $debug;
4242
$this->charset = $charset ?: ini_get('default_charset') ?: 'UTF-8';
43-
$this->fileLinkFormat = $fileLinkFormat ?: ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format');
43+
$this->fileLinkFormat = $fileLinkFormat;
4444
}
4545

4646
/**
@@ -355,13 +355,29 @@ private function formatClass($class)
355355
private function formatPath($path, $line)
356356
{
357357
$file = $this->escapeHtml(preg_match('#[^/\\\\]*+$#', $path, $file) ? $file[0] : $path);
358-
$fmt = $this->fileLinkFormat;
358+
$fmt = $this->fileLinkFormat ?: ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format');
359+
360+
if (!$fmt) {
361+
return sprintf('<span class="block trace-file-path">in <a title="%s%3$s"><strong>%s</strong>%s</a></span>', $this->escapeHtml($path), $file, 0 < $line ? ' line '.$line : '');
362+
}
363+
364+
if (\is_string($fmt)) {
365+
$i = strpos($f = $fmt, '&', max(strrpos($f, '%f'), strrpos($f, '%l'))) ?: strlen($f);
366+
$fmt = array(substr($f, 0, $i)) + preg_split('/&([^>]++)>/', substr($f, $i), -1, PREG_SPLIT_DELIM_CAPTURE);
367+
368+
for ($i = 1; isset($fmt[$i]); ++$i) {
369+
if (0 === strpos($path, $k = $fmt[$i++])) {
370+
$path = substr_replace($path, $fmt[$i], 0, strlen($k));
371+
break;
372+
}
373+
}
359374

360-
if ($fmt && $link = is_string($fmt) ? strtr($fmt, array('%f' => $path, '%l' => $line)) : $fmt->format($path, $line)) {
361-
return sprintf('<span class="block trace-file-path">in <a href="%s" title="Go to source">%s (line %d)</a></span>', $this->escapeHtml($link), $file, $line);
375+
$link = strtr($fmt[0], array('%f' => $path, '%l' => $line));
376+
} else {
377+
$link = $fmt->format($path, $line);
362378
}
363379

364-
return sprintf('<span class="block trace-file-path">in <a title="%s line %3$d"><strong>%s</strong> (line %d)</a></span>', $this->escapeHtml($path), $file, $line);
380+
return sprintf('<span class="block trace-file-path">in <a href="%s" title="Go to source"><strong>%s</string>%s</a></span>', $this->escapeHtml($link), $file, 0 < $line ? ' line '.$line : '');
365381
}
366382

367383
/**

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy