Skip to content

Commit 81c102d

Browse files
committed
[ErrorHandler] Improve fileLinkFormat handling (#50619)
- Avoid repeating file link format guessing (logic is already in FileLinkFormatter class) - Always set a fileLinkFormat to a FileLinkFormatter object to handle path mappings properly
1 parent e0cb460 commit 81c102d

File tree

2 files changed

+47
-4
lines changed

2 files changed

+47
-4
lines changed

src/Symfony/Component/ErrorHandler/ErrorRenderer/HtmlErrorRenderer.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ public function __construct(bool|callable $debug = false, string $charset = null
5252
{
5353
$this->debug = \is_bool($debug) ? $debug : $debug(...);
5454
$this->charset = $charset ?: (\ini_get('default_charset') ?: 'UTF-8');
55-
$fileLinkFormat ??= $_ENV['SYMFONY_IDE'] ?? $_SERVER['SYMFONY_IDE'] ?? null;
56-
$this->fileLinkFormat = \is_string($fileLinkFormat)
57-
? (ErrorRendererInterface::IDE_LINK_FORMATS[$fileLinkFormat] ?? $fileLinkFormat ?: false)
58-
: ($fileLinkFormat ?: \ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format') ?: false);
55+
$this->fileLinkFormat = \is_string($fileLinkFormat) ? new FileLinkFormatter($fileLinkFormat) : ($fileLinkFormat ?: false);
56+
if (false === $this->fileLinkFormat) {
57+
$this->fileLinkFormat = new FileLinkFormatter();
58+
}
5959
$this->projectDir = $projectDir;
6060
$this->outputBuffer = \is_string($outputBuffer) ? $outputBuffer : $outputBuffer(...);
6161
$this->logger = $logger;

src/Symfony/Component/ErrorHandler/Tests/ErrorRenderer/HtmlErrorRendererTest.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,49 @@ public function testRender(\Throwable $exception, HtmlErrorRenderer $errorRender
2424
$this->assertStringMatchesFormat($expected, $errorRenderer->render($exception)->getAsString());
2525
}
2626

27+
/**
28+
* @dataProvider provideFileLinkFormats
29+
*/
30+
public function testFileLinkFormat(\ErrorException $exception, string $fileLinkFormat, bool $withSymfonyIde, string $expected)
31+
{
32+
if ($withSymfonyIde) {
33+
$_ENV['SYMFONY_IDE'] = $fileLinkFormat;
34+
}
35+
$errorRenderer = new HtmlErrorRenderer(true, null, $withSymfonyIde ? null : $fileLinkFormat);
36+
37+
$this->assertStringContainsString($expected, $errorRenderer->render($exception)->getAsString());
38+
}
39+
40+
public function provideFileLinkFormats(): iterable
41+
{
42+
$exception = new \ErrorException('Notice', 0, \E_USER_NOTICE);
43+
44+
yield 'file link format set as known IDE with SYMFONY_IDE' => [
45+
$exception,
46+
'vscode',
47+
true,
48+
'href="vscode://file/'.__DIR__,
49+
];
50+
yield 'file link format set as a raw format with SYMFONY_IDE' => [
51+
$exception,
52+
'phpstorm://open?file=%f&line=%l',
53+
true,
54+
'href="phpstorm://open?file='.__DIR__,
55+
];
56+
yield 'file link format set as known IDE without SYMFONY_IDE' => [
57+
$exception,
58+
'vscode',
59+
false,
60+
'href="vscode://file/'.__DIR__,
61+
];
62+
yield 'file link format set as a raw format without SYMFONY_IDE' => [
63+
$exception,
64+
'phpstorm://open?file=%f&line=%l',
65+
false,
66+
'href="phpstorm://open?file='.__DIR__,
67+
];
68+
}
69+
2770
public static function getRenderData(): iterable
2871
{
2972
$expectedDebug = <<<HTML

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