From 4863bd30d7dc4ed5544c5f087f143f3390be1cf1 Mon Sep 17 00:00:00 2001 From: Miguel Dantas Date: Fri, 12 Jul 2019 22:22:51 +0100 Subject: [PATCH] [CORE] Fixed Media tests --- lib/mediafile.php | 10 +++++----- tests/MediaFileTest.php | 10 +++------- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/lib/mediafile.php b/lib/mediafile.php index 5086add583..fa5b653908 100644 --- a/lib/mediafile.php +++ b/lib/mediafile.php @@ -498,7 +498,7 @@ class MediaFile // From CodeIgniter // We'll need this to validate the MIME info string (e.g. text/plain; charset=us-ascii) - $regexp = '/^([a-z\-]+\/[a-z0-9\-\.\+]+)(;\s.+)?$/'; + $regexp = '/^([a-z\-]+\/[a-z0-9\-\.\+]+)(;\s[^\/]+)?$/'; /** * Fileinfo extension - most reliable method * @@ -536,7 +536,7 @@ class MediaFile */ if (DIRECTORY_SEPARATOR !== '\\') { $cmd = 'file --brief --mime '.escapeshellarg($filepath).' 2>&1'; - if (function_exists('exec')) { + if (empty($mimetype) && function_exists('exec')) { /* This might look confusing, as $mime is being populated with all of the output * when set in the second parameter. However, we only need the last line, which is * the actual return value of exec(), and as such - it overwrites anything that could @@ -548,7 +548,7 @@ class MediaFile $mimetype = $matches[1]; } } - if (function_exists('shell_exec')) { + if (empty($mimetype) && function_exists('shell_exec')) { $mime = @shell_exec($cmd); if (strlen($mime) > 0) { $mime = explode("\n", trim($mime)); @@ -557,7 +557,7 @@ class MediaFile } } } - if (function_exists('popen')) { + if (empty($mimetype) && function_exists('popen')) { $proc = @popen($cmd, 'r'); if (is_resource($proc)) { $mime = @fread($proc, 512); @@ -572,7 +572,7 @@ class MediaFile } } // Fall back to mime_content_type(), if available (still better than $_FILES[$field]['type']) - if (function_exists('mime_content_type')) { + if (empty($mimetype) && function_exists('mime_content_type')) { $mimetype = @mime_content_type($filepath); // It's possible that mime_content_type() returns FALSE or an empty string if ($mimetype == false && strlen($mimetype) > 0) { diff --git a/tests/MediaFileTest.php b/tests/MediaFileTest.php index fa6f14aba3..1e4a3c9dbb 100644 --- a/tests/MediaFileTest.php +++ b/tests/MediaFileTest.php @@ -65,21 +65,17 @@ class MediaFileTest extends PHPUnit_Framework_TestCase "image.gif" => "image/gif", "image.jpg" => "image/jpeg", "image.jpeg" => "image/jpeg", - "office.pdf" => "application/pdf", - "wordproc.odt" => "application/vnd.oasis.opendocument.text", "wordproc.ott" => "application/vnd.oasis.opendocument.text-template", "wordproc.doc" => "application/msword", "wordproc.docx" => "application/vnd.openxmlformats-officedocument.wordprocessingml.document", "wordproc.rtf" => "text/rtf", - "spreadsheet.ods" => "application/vnd.oasis.opendocument.spreadsheet", "spreadsheet.ots" => "application/vnd.oasis.opendocument.spreadsheet-template", - "spreadsheet.xls" => "application/vnd.ms-office", //"application/vnd.ms-excel", - "spreadsheet.xlt" => "application/vnd.ms-office", //"application/vnd.ms-excel", - "spreadsheet.xlsx" => "application/octet-stream", //"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", - + "spreadsheet.xls" => "application/vnd.ms-excel", + "spreadsheet.xlt" => "application/vnd.ms-excel", + "spreadsheet.xlsx" =>"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "presentation.odp" => "application/vnd.oasis.opendocument.presentation", "presentation.otp" => "application/vnd.oasis.opendocument.presentation-template", "presentation.ppt" => "application/vnd.ms-powerpoint", -- 2.39.5