Skip to content

Commit 0c05167

Browse files
author
Peter Mead
committed
Pass xdebug link to the render
The renderer can add the a tags without using an onclick attribute, which is not allowed under CSP.
1 parent 00e75ec commit 0c05167

File tree

3 files changed

+31
-29
lines changed

3 files changed

+31
-29
lines changed

src/DataCollector/RequestCollector.php

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -261,22 +261,20 @@ protected function getRouteInformation($route)
261261

262262
if (isset($reflector)) {
263263
$filename = $this->normalizeFilePath($reflector->getFileName());
264+
$result['file'] = sprintf('%s:%s-%s', $filename, $reflector->getStartLine(), $reflector->getEndLine());
264265

265266
if ($link = $this->getXdebugLink($reflector->getFileName(), $reflector->getStartLine())) {
266-
$result['file'] = sprintf(
267-
'<a href="%s" onclick="%s" class="phpdebugbar-widgets-editor-link">%s:%s-%s</a>',
268-
$link['url'],
269-
$link['ajax'] ? 'event.preventDefault();$.ajax(this.href);' : '',
270-
$filename,
271-
$reflector->getStartLine(),
272-
$reflector->getEndLine()
273-
);
267+
$result['file'] = [
268+
'value' => $result['file'],
269+
'xdebug_link' => $link,
270+
];
274271

275272
if (isset($result['controller']) && is_string($result['controller'])) {
276-
$result['controller'] .= '<a href="'.$link['url'].'" class="phpdebugbar-widgets-editor-link"></a>';
273+
$result['controller'] = [
274+
'value' => $result['controller'],
275+
'xdebug_link' => $link,
276+
];
277277
}
278-
} else {
279-
$result['file'] = sprintf('%s:%s-%s', $filename, $reflector->getStartLine(), $reflector->getEndLine());
280278
}
281279
}
282280

src/DataCollector/RouteCollector.php

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -91,22 +91,20 @@ protected function getRouteInformation($route)
9191

9292
if (isset($reflector)) {
9393
$filename = $this->normalizeFilePath($reflector->getFileName());
94+
$result['file'] = sprintf('%s:%s-%s', $filename, $reflector->getStartLine(), $reflector->getEndLine());
9495

9596
if ($link = $this->getXdebugLink($reflector->getFileName(), $reflector->getStartLine())) {
96-
$result['file'] = sprintf(
97-
'<a href="%s" onclick="%s" class="phpdebugbar-widgets-editor-link">%s:%s-%s</a>',
98-
$link['url'],
99-
$link['ajax'] ? 'event.preventDefault();$.ajax(this.href);' : '',
100-
$filename,
101-
$reflector->getStartLine(),
102-
$reflector->getEndLine()
103-
);
97+
$result['file'] = [
98+
'value' => $result['file'],
99+
'xdebug_link' => $link,
100+
];
104101

105102
if (isset($result['controller'])) {
106-
$result['controller'] .= '<a href="'.$link['url'].'" class="phpdebugbar-widgets-editor-link"></a>';
103+
$result['controller'] = [
104+
'value' => $result['controller'],
105+
'xdebug_link' => $link,
106+
];
107107
}
108-
} else {
109-
$result['file'] = sprintf('%s:%s-%s', $filename, $reflector->getStartLine(), $reflector->getEndLine());
110108
}
111109
}
112110

tests/DataCollector/RouteCollectorTest.php

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function testItCollectsRouteUri()
3636
/**
3737
* @dataProvider controllerData
3838
*/
39-
public function testItCollectsWithControllerHandler($controller, $file)
39+
public function testItCollectsWithControllerHandler($controller, $file, $url)
4040
{
4141
$this->get('web/show');
4242

@@ -45,21 +45,25 @@ public function testItCollectsWithControllerHandler($controller, $file)
4545
$this->assertNotEmpty($collected);
4646
$this->assertArrayHasKey('file', $collected);
4747
$this->assertArrayHasKey('controller', $collected);
48-
$this->assertStringContainsString($file, $collected['file']);
49-
$this->assertStringContainsString($controller, $collected['controller']);
48+
$this->assertStringContainsString($file, $collected['file']['value']);
49+
$this->assertStringContainsString($url, $collected['file']['xdebug_link']['url']);
50+
$this->assertStringContainsString($controller, $collected['controller']['value']);
51+
$this->assertStringContainsString($url, $collected['controller']['xdebug_link']['url']);
5052
}
5153

5254
/**
5355
* @dataProvider viewComponentData
5456
*/
55-
public function testItCollectsWithViewComponentHandler($controller, $file)
57+
public function testItCollectsWithViewComponentHandler($controller, $file, $url)
5658
{
5759
$this->get('web/view');
5860

5961
$collected = $this->routeCollector->collect();
6062

61-
$this->assertStringContainsString($file, $collected['file']);
62-
$this->assertStringContainsString($controller, $collected['controller']);
63+
$this->assertStringContainsString($file, $collected['file']['value']);
64+
$this->assertStringContainsString($url, $collected['file']['xdebug_link']['url']);
65+
$this->assertStringContainsString($controller, $collected['controller']['value']);
66+
$this->assertStringContainsString($url, $collected['controller']['xdebug_link']['url']);
6367
}
6468

6569
/**
@@ -75,7 +79,7 @@ public function testItCollectsWithClosureHandler($file)
7579
$this->assertArrayHasKey('uses', $collected);
7680
$this->assertArrayHasKey('file', $collected);
7781
$this->assertStringContainsString($file, $collected['uses']);
78-
$this->assertStringContainsString($file, $collected['file']);
82+
$this->assertStringContainsString($file, $collected['file']['value']);
7983
}
8084

8185
public function testItCollectsMiddleware()
@@ -93,6 +97,7 @@ public static function controllerData()
9397
{
9498
$filePath = urlencode(str_replace('\\', '/', realpath(__DIR__ . '/../Mocks/MockController.php')));
9599
return [['MockController@show',
100+
'MockController.php',
96101
sprintf('phpstorm://open?file=%s', $filePath)
97102
]];
98103
}
@@ -101,6 +106,7 @@ public static function viewComponentData()
101106
{
102107
$filePath = urlencode(str_replace('\\', '/', realpath(__DIR__ . '/../Mocks/MockViewComponent.php')));
103108
return [['MockViewComponent@render',
109+
'MockViewComponent.php',
104110
sprintf('phpstorm://open?file=%s', $filePath)
105111
]];
106112
}

0 commit comments

Comments
 (0)