Skip to content

Commit 044c5a1

Browse files
Fix HTML escaping of to-source links
1 parent 5d35c46 commit 044c5a1

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

Templating/Helper/CodeHelper.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -154,24 +154,25 @@ public function fileExcerpt($file, $line)
154154
*/
155155
public function formatFile($file, $line, $text = null)
156156
{
157+
if (PHP_VERSION_ID >= 50400) {
158+
$flags = ENT_QUOTES | ENT_SUBSTITUTE;
159+
} else {
160+
$flags = ENT_QUOTES;
161+
}
162+
157163
if (null === $text) {
158164
$file = trim($file);
159165
$fileStr = $file;
160166
if (0 === strpos($fileStr, $this->rootDir)) {
161167
$fileStr = str_replace($this->rootDir, '', str_replace('\\', '/', $fileStr));
162-
$fileStr = sprintf('<abbr title="%s">kernel.root_dir</abbr>/%s', $this->rootDir, $fileStr);
168+
$fileStr = htmlspecialchars($fileStr, $flags, $this->charset);
169+
$fileStr = sprintf('<abbr title="%s">kernel.root_dir</abbr>/%s', htmlspecialchars($this->rootDir, $flags, $this->charset), $fileStr);
163170
}
164171

165-
$text = "$fileStr at line $line";
172+
$text = sprintf('%s at line %d', $fileStr, $line);
166173
}
167174

168175
if (false !== $link = $this->getFileLink($file, $line)) {
169-
if (PHP_VERSION_ID >= 50400) {
170-
$flags = ENT_QUOTES | ENT_SUBSTITUTE;
171-
} else {
172-
$flags = ENT_QUOTES;
173-
}
174-
175176
return sprintf('<a href="%s" title="Click to open this file" class="file_link">%s</a>', htmlspecialchars($link, $flags, $this->charset), $text);
176177
}
177178

0 commit comments

Comments
 (0)