Skip to content

Commit 4796c24

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 23dfeba + 7a61c32 commit 4796c24

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

Dumper/HtmlDumper.php

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -542,16 +542,12 @@ private function getSourceLink($file, $line)
542542
return false;
543543
}
544544
if (!is_array($fileLinkFormat)) {
545-
$i = max(strpos($fileLinkFormat, '%f'), strpos($fileLinkFormat, '%l'));
546-
$i = strpos($fileLinkFormat, '#"', $i) ?: strlen($fileLinkFormat);
547-
$fileLinkFormat = array(substr($fileLinkFormat, 0, $i), substr($fileLinkFormat, $i + 1));
548-
$fileLinkFormat[1] = @json_decode('{'.$fileLinkFormat[1].'}', true) ?: array();
549-
$this->extraDisplayOptions['fileLinkFormat'] = $fileLinkFormat;
545+
$i = strpos($f = $fileLinkFormat, '&', max(strrpos($f, '%f'), strrpos($f, '%l'))) ?: strlen($f);
546+
$fileLinkFormat = array(substr($f, 0, $i)) + preg_split('/&([^>]++)>/', substr($f, $i), -1, PREG_SPLIT_DELIM_CAPTURE);
550547
}
551-
552-
foreach ($fileLinkFormat[1] as $k => $v) {
553-
if (0 === strpos($file, $k)) {
554-
$file = substr_replace($file, $v, 0, strlen($k));
548+
for ($i = 1; isset($fileLinkFormat[$i]); ++$i) {
549+
if (0 === strpos($file, $k = $fileLinkFormat[$i++])) {
550+
$file = substr_replace($file, $fileLinkFormat[$i], 0, strlen($k));
555551
break;
556552
}
557553
}

0 commit comments

Comments
 (0)