]> source.dussan.org Git - nextcloud-server.git/commitdiff
Correctly remove the charset from finfo mimetype
authorJoas Schilling <coding@schilljs.com>
Fri, 2 Sep 2016 11:29:30 +0000 (13:29 +0200)
committerJoas Schilling <coding@schilljs.com>
Thu, 8 Sep 2016 07:20:34 +0000 (09:20 +0200)
lib/private/Files/Type/Detection.php
tests/lib/Files/Type/DetectionTest.php

index 492025b7bfc30f2268a723e0db0ec8a1338b175e..66ef0dd2aabfab71fbe44c6e7d2a1d367fd50392 100644 (file)
@@ -200,7 +200,7 @@ class Detection implements IMimeTypeDetector {
                        $info = @strtolower(finfo_file($finfo, $path));
                        finfo_close($finfo);
                        if ($info) {
-                               $mimeType = substr($info, 0, strpos($info, ';'));
+                               $mimeType = strpos($info, ';') !== false ? substr($info, 0, strpos($info, ';')) : $info;
                                return empty($mimeType) ? 'application/octet-stream' : $mimeType;
                        }
 
@@ -238,7 +238,8 @@ class Detection implements IMimeTypeDetector {
        public function detectString($data) {
                if (function_exists('finfo_open') and function_exists('finfo_file')) {
                        $finfo = finfo_open(FILEINFO_MIME);
-                       return finfo_buffer($finfo, $data);
+                       $info = finfo_buffer($finfo, $data);
+                       return strpos($info, ';') !== false ? substr($info, 0, strpos($info, ';')) : $info;
                } else {
                        $tmpFile = \OC::$server->getTempManager()->getTemporaryFile();
                        $fh = fopen($tmpFile, 'wb');
index 7b9dc1b3e4d47e6b7aff89ef39ec3903cb886b4b..11267ee2e7dfcef721575f3df6686ff89d0a535f 100644 (file)
@@ -81,7 +81,7 @@ class DetectionTest extends \Test\TestCase {
 
        public function testDetectString() {
                $result = $this->detection->detectString("/data/data.tar.gz");
-               $expected = 'text/plain; charset=us-ascii';
+               $expected = 'text/plain';
                $this->assertEquals($expected, $result);
        }