From 810f99c1c906b754d89df675965febe820f0bcda Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 2 Sep 2016 13:29:30 +0200 Subject: [PATCH] Correctly remove the charset from finfo mimetype --- lib/private/Files/Type/Detection.php | 5 +++-- tests/lib/Files/Type/DetectionTest.php | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/private/Files/Type/Detection.php b/lib/private/Files/Type/Detection.php index 492025b7bf..66ef0dd2aa 100644 --- a/lib/private/Files/Type/Detection.php +++ b/lib/private/Files/Type/Detection.php @@ -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'); diff --git a/tests/lib/Files/Type/DetectionTest.php b/tests/lib/Files/Type/DetectionTest.php index 7b9dc1b3e4..11267ee2e7 100644 --- a/tests/lib/Files/Type/DetectionTest.php +++ b/tests/lib/Files/Type/DetectionTest.php @@ -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); }