diff --git a/src/Symfony/Bridge/Twig/Extension/CodeExtension.php b/src/Symfony/Bridge/Twig/Extension/CodeExtension.php index fade3b679633..61a240611d9e 100644 --- a/src/Symfony/Bridge/Twig/Extension/CodeExtension.php +++ b/src/Symfony/Bridge/Twig/Extension/CodeExtension.php @@ -33,10 +33,8 @@ public function __construct($fileLinkFormat, $rootDir, $charset) { $fileLinkFormat = $fileLinkFormat ?: ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format'); if ($fileLinkFormat && !is_array($fileLinkFormat)) { - $i = max(strpos($fileLinkFormat, '%f'), strpos($fileLinkFormat, '%l')); - $i = strpos($fileLinkFormat, '#"', $i) ?: strlen($fileLinkFormat); - $fileLinkFormat = array(substr($fileLinkFormat, 0, $i), substr($fileLinkFormat, $i + 1)); - $fileLinkFormat[1] = @json_decode('{'.$fileLinkFormat[1].'}', true) ?: array(); + $i = strpos($f = $fileLinkFormat, '&', max(strrpos($f, '%f'), strrpos($f, '%l'))) ?: strlen($f); + $fileLinkFormat = array(substr($f, 0, $i)) + preg_split('/&([^>]++)>/', substr($f, $i), -1, PREG_SPLIT_DELIM_CAPTURE); } $this->fileLinkFormat = $fileLinkFormat; $this->rootDir = str_replace('/', DIRECTORY_SEPARATOR, dirname($rootDir)).DIRECTORY_SEPARATOR; @@ -198,9 +196,9 @@ public function formatFile($file, $line, $text = null) public function getFileLink($file, $line) { if ($this->fileLinkFormat && file_exists($file)) { - foreach ($this->fileLinkFormat[1] as $k => $v) { - if (0 === strpos($file, $k)) { - $file = substr_replace($file, $v, 0, strlen($k)); + for ($i = 1; isset($this->fileLinkFormat[$i]); ++$i) { + if (0 === strpos($file, $k = $this->fileLinkFormat[$i++])) { + $file = substr_replace($file, $this->fileLinkFormat[$i], 0, strlen($k)); break; } } diff --git a/src/Symfony/Bridge/Twig/Tests/Extension/CodeExtensionTest.php b/src/Symfony/Bridge/Twig/Tests/Extension/CodeExtensionTest.php index 15536a62beb3..2c059541e712 100644 --- a/src/Symfony/Bridge/Twig/Tests/Extension/CodeExtensionTest.php +++ b/src/Symfony/Bridge/Twig/Tests/Extension/CodeExtensionTest.php @@ -64,6 +64,6 @@ public function testGetName() protected function getExtension() { - return new CodeExtension('proto://%f#&line=%l#'.json_encode(substr(__FILE__, 0, 5)).':"foobar"', '/root', 'UTF-8'); + return new CodeExtension('proto://%f#&line=%l&'.substr(__FILE__, 0, 5).'>foobar', '/root', 'UTF-8'); } } diff --git a/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/CodeHelper.php b/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/CodeHelper.php index 3487e5d6073a..62efcd6f10b4 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/CodeHelper.php +++ b/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/CodeHelper.php @@ -35,10 +35,8 @@ public function __construct($fileLinkFormat, $rootDir, $charset) { $fileLinkFormat = $fileLinkFormat ?: ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format'); if ($fileLinkFormat && !is_array($fileLinkFormat)) { - $i = max(strpos($fileLinkFormat, '%f'), strpos($fileLinkFormat, '%l')); - $i = strpos($fileLinkFormat, '#"', $i) ?: strlen($fileLinkFormat); - $fileLinkFormat = array(substr($fileLinkFormat, 0, $i), substr($fileLinkFormat, $i + 1)); - $fileLinkFormat[1] = @json_decode('{'.$fileLinkFormat[1].'}', true) ?: array(); + $i = strpos($f = $fileLinkFormat, '&', max(strrpos($f, '%f'), strrpos($f, '%l'))) ?: strlen($f); + $fileLinkFormat = array(substr($f, 0, $i)) + preg_split('/&([^>]++)>/', substr($f, $i), -1, PREG_SPLIT_DELIM_CAPTURE); } $this->fileLinkFormat = $fileLinkFormat; $this->rootDir = str_replace('\\', '/', $rootDir).'/'; @@ -193,9 +191,9 @@ public function formatFile($file, $line, $text = null) public function getFileLink($file, $line) { if ($this->fileLinkFormat && is_file($file)) { - foreach ($this->fileLinkFormat[1] as $k => $v) { - if (0 === strpos($file, $k)) { - $file = substr_replace($file, $v, 0, strlen($k)); + for ($i = 1; isset($this->fileLinkFormat[$i]); ++$i) { + if (0 === strpos($file, $k = $this->fileLinkFormat[$i++])) { + $file = substr_replace($path, $this->fileLinkFormat[$i], 0, strlen($k)); break; } } diff --git a/src/Symfony/Component/Debug/ExceptionHandler.php b/src/Symfony/Component/Debug/ExceptionHandler.php index 1c0087bba927..900d64d9df0f 100644 --- a/src/Symfony/Component/Debug/ExceptionHandler.php +++ b/src/Symfony/Component/Debug/ExceptionHandler.php @@ -39,10 +39,8 @@ public function __construct($debug = true, $charset = null, $fileLinkFormat = nu { $fileLinkFormat = $fileLinkFormat ?: ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format'); if ($fileLinkFormat && !is_array($fileLinkFormat)) { - $i = max(strpos($fileLinkFormat, '%f'), strpos($fileLinkFormat, '%l')); - $i = strpos($fileLinkFormat, '#"', $i) ?: strlen($fileLinkFormat); - $fileLinkFormat = array(substr($fileLinkFormat, 0, $i), substr($fileLinkFormat, $i + 1)); - $fileLinkFormat[1] = @json_decode('{'.$fileLinkFormat[1].'}', true) ?: array(); + $i = strpos($f = $fileLinkFormat, '&', max(strrpos($f, '%f'), strrpos($f, '%l'))) ?: strlen($f); + $fileLinkFormat = array(substr($f, 0, $i)) + preg_split('/&([^>]++)>/', substr($f, $i), -1, PREG_SPLIT_DELIM_CAPTURE); } $this->debug = $debug; $this->charset = $charset ?: ini_get('default_charset') ?: 'UTF-8'; @@ -97,9 +95,8 @@ public function setFileLinkFormat($fileLinkFormat) { $old = $this->fileLinkFormat; if ($fileLinkFormat && !is_array($fileLinkFormat)) { - $i = strpos($fileLinkFormat, '#"') ?: strlen($fileLinkFormat); - $fileLinkFormat = array(substr($fileLinkFormat, 0, $i), substr($fileLinkFormat, $i + 1)); - $fileLinkFormat[1] = @json_decode('{'.$fileLinkFormat[1].'}', true) ?: array(); + $i = strpos($f = $fileLinkFormat, '&', max(strrpos($f, '%f'), strrpos($f, '%l'))) ?: strlen($f); + $fileLinkFormat = array(substr($f, 0, $i)) + preg_split('/&([^>]++)>/', substr($f, $i), -1, PREG_SPLIT_DELIM_CAPTURE); } $this->fileLinkFormat = $fileLinkFormat; if ($old) { @@ -368,9 +365,9 @@ private function formatPath($path, $line) $file = $this->escapeHtml(preg_match('#[^/\\\\]*+$#', $path, $file) ? $file[0] : $path); if ($fileLinkFormat = $this->fileLinkFormat) { - foreach ($fileLinkFormat[1] as $k => $v) { - if (0 === strpos($path, $k)) { - $path = substr_replace($path, $v, 0, strlen($k)); + for ($i = 1; isset($fileLinkFormat[$i]); ++$i) { + if (0 === strpos($path, $k = $fileLinkFormat[$i++])) { + $path = substr_replace($path, $fileLinkFormat[$i], 0, strlen($k)); break; } } diff --git a/src/Symfony/Component/HttpKernel/DataCollector/DumpDataCollector.php b/src/Symfony/Component/HttpKernel/DataCollector/DumpDataCollector.php index fde463e6f46d..b76280c56a9c 100644 --- a/src/Symfony/Component/HttpKernel/DataCollector/DumpDataCollector.php +++ b/src/Symfony/Component/HttpKernel/DataCollector/DumpDataCollector.php @@ -42,10 +42,8 @@ public function __construct(Stopwatch $stopwatch = null, $fileLinkFormat = null, { $fileLinkFormat = $fileLinkFormat ?: ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format'); if ($fileLinkFormat && !is_array($fileLinkFormat)) { - $i = max(strpos($fileLinkFormat, '%f'), strpos($fileLinkFormat, '%l')); - $i = strpos($fileLinkFormat, '#"', $i) ?: strlen($fileLinkFormat); - $fileLinkFormat = array(substr($fileLinkFormat, 0, $i), substr($fileLinkFormat, $i + 1)); - $fileLinkFormat[1] = @json_decode('{'.$fileLinkFormat[1].'}', true) ?: array(); + $i = strpos($f = $fileLinkFormat, '&', max(strrpos($f, '%f'), strrpos($f, '%l'))) ?: strlen($f); + $fileLinkFormat = array(substr($f, 0, $i)) + preg_split('/&([^>]++)>/', substr($f, $i), -1, PREG_SPLIT_DELIM_CAPTURE); } $this->stopwatch = $stopwatch; $this->fileLinkFormat = $fileLinkFormat; @@ -268,9 +266,9 @@ private function doDump($data, $name, $file, $line) $name = strip_tags($this->style('', $name)); $file = strip_tags($this->style('', $file)); if ($fileLinkFormat) { - foreach ($fileLinkFormat[1] as $k => $v) { - if (0 === strpos($file, $k)) { - $file = substr_replace($file, $v, 0, strlen($k)); + for ($i = 1; isset($fileLinkFormat[$i]); ++$i) { + if (0 === strpos($file, $k = $fileLinkFormat[$i++])) { + $file = substr_replace($file, $fileLinkFormat[$i], 0, strlen($k)); break; } } diff --git a/src/Symfony/Component/VarDumper/Dumper/HtmlDumper.php b/src/Symfony/Component/VarDumper/Dumper/HtmlDumper.php index 1b9c6b602c2f..dd7c4691d1bb 100644 --- a/src/Symfony/Component/VarDumper/Dumper/HtmlDumper.php +++ b/src/Symfony/Component/VarDumper/Dumper/HtmlDumper.php @@ -542,16 +542,12 @@ private function getSourceLink($file, $line) return false; } if (!is_array($fileLinkFormat)) { - $i = max(strpos($fileLinkFormat, '%f'), strpos($fileLinkFormat, '%l')); - $i = strpos($fileLinkFormat, '#"', $i) ?: strlen($fileLinkFormat); - $fileLinkFormat = array(substr($fileLinkFormat, 0, $i), substr($fileLinkFormat, $i + 1)); - $fileLinkFormat[1] = @json_decode('{'.$fileLinkFormat[1].'}', true) ?: array(); - $this->extraDisplayOptions['fileLinkFormat'] = $fileLinkFormat; + $i = strpos($f = $fileLinkFormat, '&', max(strrpos($f, '%f'), strrpos($f, '%l'))) ?: strlen($f); + $fileLinkFormat = array(substr($f, 0, $i)) + preg_split('/&([^>]++)>/', substr($f, $i), -1, PREG_SPLIT_DELIM_CAPTURE); } - - foreach ($fileLinkFormat[1] as $k => $v) { - if (0 === strpos($file, $k)) { - $file = substr_replace($file, $v, 0, strlen($k)); + for ($i = 1; isset($fileLinkFormat[$i]); ++$i) { + if (0 === strpos($file, $k = $fileLinkFormat[$i++])) { + $file = substr_replace($file, $fileLinkFormat[$i], 0, strlen($k)); break; } }