From 0c05167d25228f804884780e5e4b36b830a92ddd Mon Sep 17 00:00:00 2001 From: Peter Mead Date: Wed, 26 Nov 2025 12:39:39 +0000 Subject: [PATCH] Pass xdebug link to the render The renderer can add the a tags without using an onclick attribute, which is not allowed under CSP. --- src/DataCollector/RequestCollector.php | 20 +++++++++----------- src/DataCollector/RouteCollector.php | 20 +++++++++----------- tests/DataCollector/RouteCollectorTest.php | 20 +++++++++++++------- 3 files changed, 31 insertions(+), 29 deletions(-) diff --git a/src/DataCollector/RequestCollector.php b/src/DataCollector/RequestCollector.php index f3ae8b513..0411974dc 100644 --- a/src/DataCollector/RequestCollector.php +++ b/src/DataCollector/RequestCollector.php @@ -261,22 +261,20 @@ protected function getRouteInformation($route) if (isset($reflector)) { $filename = $this->normalizeFilePath($reflector->getFileName()); + $result['file'] = sprintf('%s:%s-%s', $filename, $reflector->getStartLine(), $reflector->getEndLine()); if ($link = $this->getXdebugLink($reflector->getFileName(), $reflector->getStartLine())) { - $result['file'] = sprintf( - '%s:%s-%s', - $link['url'], - $link['ajax'] ? 'event.preventDefault();$.ajax(this.href);' : '', - $filename, - $reflector->getStartLine(), - $reflector->getEndLine() - ); + $result['file'] = [ + 'value' => $result['file'], + 'xdebug_link' => $link, + ]; if (isset($result['controller']) && is_string($result['controller'])) { - $result['controller'] .= ''; + $result['controller'] = [ + 'value' => $result['controller'], + 'xdebug_link' => $link, + ]; } - } else { - $result['file'] = sprintf('%s:%s-%s', $filename, $reflector->getStartLine(), $reflector->getEndLine()); } } diff --git a/src/DataCollector/RouteCollector.php b/src/DataCollector/RouteCollector.php index f548a795e..82a95302e 100644 --- a/src/DataCollector/RouteCollector.php +++ b/src/DataCollector/RouteCollector.php @@ -91,22 +91,20 @@ protected function getRouteInformation($route) if (isset($reflector)) { $filename = $this->normalizeFilePath($reflector->getFileName()); + $result['file'] = sprintf('%s:%s-%s', $filename, $reflector->getStartLine(), $reflector->getEndLine()); if ($link = $this->getXdebugLink($reflector->getFileName(), $reflector->getStartLine())) { - $result['file'] = sprintf( - '%s:%s-%s', - $link['url'], - $link['ajax'] ? 'event.preventDefault();$.ajax(this.href);' : '', - $filename, - $reflector->getStartLine(), - $reflector->getEndLine() - ); + $result['file'] = [ + 'value' => $result['file'], + 'xdebug_link' => $link, + ]; if (isset($result['controller'])) { - $result['controller'] .= ''; + $result['controller'] = [ + 'value' => $result['controller'], + 'xdebug_link' => $link, + ]; } - } else { - $result['file'] = sprintf('%s:%s-%s', $filename, $reflector->getStartLine(), $reflector->getEndLine()); } } diff --git a/tests/DataCollector/RouteCollectorTest.php b/tests/DataCollector/RouteCollectorTest.php index 7515b3caa..20631e4a4 100644 --- a/tests/DataCollector/RouteCollectorTest.php +++ b/tests/DataCollector/RouteCollectorTest.php @@ -36,7 +36,7 @@ public function testItCollectsRouteUri() /** * @dataProvider controllerData */ - public function testItCollectsWithControllerHandler($controller, $file) + public function testItCollectsWithControllerHandler($controller, $file, $url) { $this->get('web/show'); @@ -45,21 +45,25 @@ public function testItCollectsWithControllerHandler($controller, $file) $this->assertNotEmpty($collected); $this->assertArrayHasKey('file', $collected); $this->assertArrayHasKey('controller', $collected); - $this->assertStringContainsString($file, $collected['file']); - $this->assertStringContainsString($controller, $collected['controller']); + $this->assertStringContainsString($file, $collected['file']['value']); + $this->assertStringContainsString($url, $collected['file']['xdebug_link']['url']); + $this->assertStringContainsString($controller, $collected['controller']['value']); + $this->assertStringContainsString($url, $collected['controller']['xdebug_link']['url']); } /** * @dataProvider viewComponentData */ - public function testItCollectsWithViewComponentHandler($controller, $file) + public function testItCollectsWithViewComponentHandler($controller, $file, $url) { $this->get('web/view'); $collected = $this->routeCollector->collect(); - $this->assertStringContainsString($file, $collected['file']); - $this->assertStringContainsString($controller, $collected['controller']); + $this->assertStringContainsString($file, $collected['file']['value']); + $this->assertStringContainsString($url, $collected['file']['xdebug_link']['url']); + $this->assertStringContainsString($controller, $collected['controller']['value']); + $this->assertStringContainsString($url, $collected['controller']['xdebug_link']['url']); } /** @@ -75,7 +79,7 @@ public function testItCollectsWithClosureHandler($file) $this->assertArrayHasKey('uses', $collected); $this->assertArrayHasKey('file', $collected); $this->assertStringContainsString($file, $collected['uses']); - $this->assertStringContainsString($file, $collected['file']); + $this->assertStringContainsString($file, $collected['file']['value']); } public function testItCollectsMiddleware() @@ -93,6 +97,7 @@ public static function controllerData() { $filePath = urlencode(str_replace('\\', '/', realpath(__DIR__ . '/../Mocks/MockController.php'))); return [['MockController@show', + 'MockController.php', sprintf('phpstorm://open?file=%s', $filePath) ]]; } @@ -101,6 +106,7 @@ public static function viewComponentData() { $filePath = urlencode(str_replace('\\', '/', realpath(__DIR__ . '/../Mocks/MockViewComponent.php'))); return [['MockViewComponent@render', + 'MockViewComponent.php', sprintf('phpstorm://open?file=%s', $filePath) ]]; }