From ae4d10668e2b4c9ca953e3681bd18a3c86093481 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Fri, 17 Jan 2014 15:05:43 +0100 Subject: [PATCH] Fix mimetype detection --- lib/files/cache/cache.php | 4 ++++ lib/helper.php | 8 +++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/files/cache/cache.php b/lib/files/cache/cache.php index 32cad6b84b2..a2a7a996970 100644 --- a/lib/files/cache/cache.php +++ b/lib/files/cache/cache.php @@ -91,6 +91,10 @@ class Cache { * @return int */ public function getMimetypeId($mime) { + if (empty($mime)) { + // Can not insert empty string into Oracle NOT NULL column. + $mime = 'application/octet-stream'; + } if (!isset($this->mimetypeIds[$mime])) { $result = \OC_DB::executeAudited( 'SELECT `id` FROM `*PREFIX*mimetypes` WHERE `mimetype` = ?', diff --git a/lib/helper.php b/lib/helper.php index 71b3bd5beba..2d22f24ab38 100644 --- a/lib/helper.php +++ b/lib/helper.php @@ -390,7 +390,6 @@ class OC_Helper { * does NOT work for ownClouds filesystem, use OC_FileSystem::getMimeType instead */ static function getMimeType($path) { - $isWrapped=(strpos($path, '://')!==false) and (substr($path, 0, 7)=='file://'); if (@is_dir($path)) { // directories are easy @@ -414,9 +413,11 @@ class OC_Helper { $info = @strtolower(finfo_file($finfo, $path)); if($info) { $mimeType=substr($info, 0, strpos($info, ';')); + return empty($mimeType) ? 'application/octet-stream' : $mimeType; } finfo_close($finfo); } + $isWrapped = (strpos($path, '://') !== false) and (substr($path, 0, 7) === 'file://'); if (!$isWrapped and $mimeType=='application/octet-stream' && function_exists("mime_content_type")) { // use mime magic extension if available $mimeType = mime_content_type($path); @@ -432,6 +433,11 @@ class OC_Helper { //trim the newline $mimeType = trim($reply); + if (empty($mimeType)) { + $mimeType = 'application/octet-stream'; + } + + } return $mimeType; } -- 2.39.5