From b890c3429df5e929d11af2dedebfec15a885c550 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Sun, 26 Sep 2010 20:19:05 +0200 Subject: [PATCH] [FrameworkBundle] fixed file detection and formatting in Code helper --- .../Templating/Helper/CodeHelper.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/CodeHelper.php b/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/CodeHelper.php index 9a8af499a1..57639d2979 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/CodeHelper.php +++ b/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/CodeHelper.php @@ -158,9 +158,11 @@ class CodeHelper extends Helper */ public function formatFile($file, $line) { - if (0 === strpos($file, $this->rootDir)) { - $file = str_replace($this->rootDir, '', str_replace('\\', '/', $file)); - $file = sprintf('kernel.root_dir/%s', $this->rootDir, $file); + $file = trim($file); + $fileStr = $file; + if (0 === strpos($fileStr, $this->rootDir)) { + $fileStr = str_replace($this->rootDir, '', str_replace('\\', '/', $fileStr)); + $fileStr = sprintf('kernel.root_dir/%s', $this->rootDir, $fileStr); } if (!$this->fileLinkFormat) { @@ -169,15 +171,15 @@ class CodeHelper extends Helper $link = strtr($this->fileLinkFormat, array('%f' => $file, '%l' => $line)); - return sprintf('%s line %s', $link, $file, $line); + return sprintf('%s line %s', $link, $fileStr, $line); } public function formatFileFromText($text) { $that = $this; - return preg_replace_callback('/(called|defined) in (.*?)(?: on)? line (\d+)/', function ($match) use ($that) { - return $match[1].' in '.$that->formatFile($match[2], $match[3]); + return preg_replace_callback('/in (.*?)(?: on|at)? line (\d+)/', function ($match) use ($that) { + return 'in '.$that->formatFile($match[1], $match[2]); }, $text); }