8000 merged branch francisbesset/check_mime_type (PR #6345) · symfony/symfony@da98371 · GitHub
[go: up one dir, main page]

Skip to content

Commit da98371

Browse files
committed
merged branch francisbesset/check_mime_type (PR #6345)
This PR was merged into the 2.0 branch. Commits ------- d3f5f3a Added comment 773d818 [FrameworkBundle] Added a check on file mime type for CodeHelper::fileExcerpt() Discussion ---------- [FrameworkBundle] Added a check on file mime type for CodeHelper::fileExcerpt() Fixed a bug on `CodeHelper::fileExcerpt()`. I add a check on the file mime type because I use a phar of phpunit and when a exception throwed in a test, Symfony build a page with the stack trace of the exception. The phpunit.phar path is in the stack trace and Symfony call `highlight_file()` function on this file path. `highlight_file()` cannot parse the phar file and warnings are displayed. This PR add a check on the file mime type. **This PR can be applied on 2.0, 2.1 and master branches.** Bug fix: yes Feature addition: no Backwards compatibility break: no Symfony2 tests pass: yes (The broken test seems to be unrelated to this change) Fixes the following tickets: - License of the code: MIT
2 parents af7f75f + d3f5f3a commit da98371

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/Symfony/Bundle/FrameworkBundle/Templating/Helper/CodeHelper.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,15 @@ public function formatArgs(array $args)
143143
public function fileExcerpt($file, $line)
144144
{
145145
if (is_readable($file)) {
146+
if (extension_loaded('fileinfo')) {
147+
$finfo = new \Finfo();
148+
149+
// Check if the file is an application/octet-stream (eg. Phar file) because hightlight_file cannot parse these files
150+
if ('application/octet-stream' === $finfo->file($file, FILEINFO_MIME_TYPE)) {
151+
return;
152+
}
153+
}
154+
146155
$code = highlight_file($file, true);
147156
// remove main code/span tags
148157
$code = preg_replace('#^<code.*?>\s*<span.*?>(.*)</span>\s*</code>#s', '\\1', $code);

0 commit comments

Comments
 (0)
0