8000 bug #29317 [WebProfiler] Detect non-file paths in file viewer (ro0NL) · symfony/symfony@f747ea9 · GitHub
[go: up one dir, main page]

Skip to content

Commit f747ea9

Browse files
committed
bug #29317 [WebProfiler] Detect non-file paths in file viewer (ro0NL)
This PR was merged into the 3.4 branch. Discussion ---------- [WebProfiler] Detect non-file paths in file viewer | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no <!-- see https://symfony.com/bc --> | Deprecations? | no | Tests pass? | yes <!-- please add some, will be required by reviewers --> | Fixed tickets | #... <!-- #-prefixed issue number(s), if any --> | License | MIT | Doc PR | symfony/symfony-docs#... <!-- required for new features --> We actually link directories sometimes :) now looks like: ![image](https://user-images.githubusercontent.com/1047696/48981263-7b2b4880-f0d3-11e8-9334-9e2f45d62c09.png) Commits ------- 71aade3 [WebProfiler] Detect empty file paths in file viewer
2 parents 511b070 + 71aade3 commit f747ea9

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

src/Symfony/Bridge/Twig/Extension/CodeExtension.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public function formatArgsAsText($args)
134134
*/
135135
public function fileExcerpt($file, $line, $srcContext = 3)
136136
{
137-
if (is_readable($file)) {
137+
if (is_file($file) && is_readable($file)) {
138138
// highlight_file could throw warnings
139139
// see https://bugs.php.net/bug.php?id=25725
140140
$code = @highlight_file($file, true);
@@ -157,6 +157,8 @@ public function fileExcerpt($file, $line, $srcContext = 3)
157157

158158
return '<ol start="'.max($line - $srcContext, 1).'">'.implode("\n", $lines).'</ol>';
159159
}
160+
161+
return null;
160162
}
161163

162164
/**

src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/open.css.twig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ a.doc:hover {
5454
text-decoration: underline;
5555
}
5656

57+
.empty {
58+
padding: 10px;
59+
color: #555;
60+
}
61+
5762
.source {
5863
margin-top: 41px;
5964
}

src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/open.html.twig

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,16 @@
77
{% endblock %}
88

99
{% block body %}
10-
<div class="header">
11-
<h1>{{ file }}{% if 0 < line %} <small>line {{ line }}</small>{% endif %}</h1>
12-
<a class="doc" href="https://symfony.com/doc/{{ constant('Symfony\\Component\\HttpKernel\\Kernel::VERSION') }}/reference/configuration/framework.html#ide" rel="help">Open in your IDE?</a>
13-
</div>
14-
<div class="source">
15-
{{ filename|file_excerpt(line, -1) }}
16-
</div>
10+
{% set source = filename|file_excerpt(line, -1) %}
11+
<div class="header">
12+
<h1>{{ file }}{% if 0 < line %} <small>line {{ line }}</small>{% endif %}</h1>
13+
<a class="doc" href="https://symfony.com/doc/{{ constant('Symfony\\Component\\HttpKernel\\Kernel::VERSION') }}/reference/configuration/framework.html#ide" rel="help">Open in your IDE?</a>
14+
</div>
15+
<div class="source">
16+
{% if source is null %}
17+
<p class="empty">The file is not readable.</p>
18+
{% else %}
19+
{{ source|raw }}
20+
{% endif %}
21+
</div>
1722
{% endblock %}

0 commit comments

Comments
 (0)
0