Skip to content

Commit a7faca2

Browse files
committed
minor #20101 Simplified link-to-source mapping definitions in debug.file_link_format (nicolas-grekas)
This PR was merged into the 3.2-dev branch. Discussion ---------- Simplified link-to-source mapping definitions in debug.file_link_format | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #19950 | License | MIT | Doc PR | symfony/symfony-docs#7019 Having to json_encode here (or any other kind of encoding) is really tedious to deal with: it makes it hard to have things working quickly. `%f` and `%l` aren't encoded anyway, so let's use very unlikely chars as separators here also instead. Commits ------- 27df38e Simplified link-to-source mapping definitions in debug.file_link_format
2 parents 0595272 + 62646a5 commit a7faca2

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

Extension/CodeExtension.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,8 @@ public function __construct($fileLinkFormat, $rootDir, $charset)
3333
{
3434
$fileLinkFormat = $fileLinkFormat ?: ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format');
3535
if ($fileLinkFormat && !is_array($fileLinkFormat)) {
36-
$i = max(strpos($fileLinkFormat, '%f'), strpos($fileLinkFormat, '%l'));
37-
$i = strpos($fileLinkFormat, '#"', $i) ?: strlen($fileLinkFormat);
38-
$fileLinkFormat = array(substr($fileLinkFormat, 0, $i), substr($fileLinkFormat, $i + 1));
39-
$fileLinkFormat[1] = @json_decode('{'.$fileLinkFormat[1].'}', true) ?: array();
36+
$i = strpos($f = $fileLinkFormat, '&', max(strrpos($f, '%f'), strrpos($f, '%l'))) ?: strlen($f);
37+
$fileLinkFormat = array(substr($f, 0, $i)) + preg_split('/&([^>]++)>/', substr($f, $i), -1, PREG_SPLIT_DELIM_CAPTURE);
4038
}
4139
$this->fileLinkFormat = $fileLinkFormat;
4240
$this->rootDir = str_replace('/', DIRECTORY_SEPARATOR, dirname($rootDir)).DIRECTORY_SEPARATOR;
@@ -198,9 +196,9 @@ public function formatFile($file, $line, $text = null)
198196
public function getFileLink($file, $line)
199197
{
200198
if ($this->fileLinkFormat && file_exists($file)) {
201-
foreach ($this->fileLinkFormat[1] as $k => $v) {
202-
if (0 === strpos($file, $k)) {
203-
$file = substr_replace($file, $v, 0, strlen($k));
199+
for ($i = 1; isset($this->fileLinkFormat[$i]); ++$i) {
200+
if (0 === strpos($file, $k = $this->fileLinkFormat[$i++])) {
201+
$file = substr_replace($file, $this->fileLinkFormat[$i], 0, strlen($k));
204202
break;
205203
}
206204
}

Tests/Extension/CodeExtensionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,6 @@ public function testGetName()
6464

6565
protected function getExtension()
6666
{
67-
return new CodeExtension('proto://%f#&line=%l#'.json_encode(substr(__FILE__, 0, 5)).':"foobar"', '/root', 'UTF-8');
67+
return new CodeExtension('proto://%f#&line=%l&'.substr(__FILE__, 0, 5).'>foobar', '/root', 'UTF-8');
6868
}
6969
}

0 commit comments

Comments
 (0)