8000 minor #26 Fix the escaping of the source code when displaying it (stof) · SofHad/symfony@427fe5a · GitHub
[go: up one dir, main page]

Skip to content

Commit 427fe5a

Browse files
committed
minor symfony#26 Fix the escaping of the source code when displaying it (stof)
This PR was merged into the master branch. Discussion ---------- Fix the escaping of the source code when displaying it The source code of the controller cannot be considered as being safe HTML. It needs to be escaped. This also moves the escaping of the template source code from the extension to the template rendering it, where it belongs (which also avoid using ``|raw``, which is flagged by Insight as being dangerous because it expects the escaping to happen elsewhere, see the first point about the controller source code) Commits ------- 2d0965e Fix the escaping of the source code when displaying it
2 parents a4c538d + 2d0965e commit 427fe5a

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

app/Resources/views/default/_source_code.html.twig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020

2121
<div class="modal-body">
2222
<h3>Controller code <small class="pull-right">{{ controller_file_path }}</small></h3>
23-
<pre><code class="php">{{ controller_source_code|raw }}</code></pre>
23+
<pre><code class="php">{{ controller_source_code }}</code></pre>
2424

2525
<h3>Twig template code <small class="pull-right">{{ template_file_path }}</small></h3>
26-
<pre><code class="twig">{{ template_source_code|raw }}</code></pre>
26+
<pre><code class="twig">{{ template_source_code }}</code></pre>
2727
</div>
2828
</div>
2929
</div>

src/AppBundle/Twig/SourceCodeExtension.php

Expand all lines: src/AppBundle/Twig/SourceCodeExtension.php
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function showSourceCode(\Twig_Environment $twig, $template)
5050
return $twig->render('default/_source_code.html.twig', array(
5151
'controller_source_code' => $this->getControllerCode(),
5252
'controller_file_path' => $this->getControllerRelativePath(),
53-
'template_source_code' => htmlspecialchars($this->getTemplateCode(), ENT_QUOTES, 'UTF-8'),
53+
'template_source_code' => $this->getTemplateCode(),
5454
'template_file_path' => $this->getTemplateRelativePath(),
5555
));
5656
}

0 commit comments

Comments
 (0)
0