$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;
}
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');
public function testDetectString() {
$result = $this->detection->detectString("/data/data.tar.gz");
- $expected = 'text/plain; charset=us-ascii';
+ $expected = 'text/plain';
$this->assertEquals($expected, $result);
}