]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
[CORE] Fixed Media tests
authorMiguel Dantas <biodantasgs@gmail.com>
Fri, 12 Jul 2019 21:22:51 +0000 (22:22 +0100)
committerDiogo Cordeiro <diogo@fc.up.pt>
Sat, 3 Aug 2019 16:31:43 +0000 (17:31 +0100)
lib/mediafile.php
tests/MediaFileTest.php

index 5086add5836ae22af256d05bda509db4b1f87e6d..fa5b653908d6250176564a7988c849bb7a139087 100644 (file)
@@ -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) {
index fa6f14aba36fd2ba3bd94ff1e84f23ee60067287..1e4a3c9dbb8d0992ddeab4dda1ac3d2551e6af69 100644 (file)
@@ -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",