File tree Expand file tree Collapse file tree 4 files changed +26
-2
lines changed
dev/tests/static/testsuite/Magento/Test/Legacy/_files/copyright
lib/internal/Magento/Framework/File Expand file tree Collapse file tree 4 files changed +26
-2
lines changed Original file line number Diff line number Diff line change 1010 '/setup\/src\/Zend\/Mvc\/Controller\/LazyControllerAbstractFactory\.php/ ' ,
1111 '/app\/code\/(?!Magento)[^\/]*/ ' ,
1212 '#dev/tests/setup-integration/testsuite/Magento/Developer/_files/\S*\.xml$# ' ,
13+ '/lib\/internal\/Magento\/Framework\/File\/Test\/Unit\/_files\/blank.html$/ '
1314];
Original file line number Diff line number Diff line change @@ -78,6 +78,18 @@ class Mime
7878 'svg ' => 'image/svg+xml ' ,
7979 ];
8080
81+ /**
82+ * List of generic MIME types
83+ *
84+ * The file mime type should be detected by the file's extension if the native mime type is one of the listed below.
85+ *
86+ * @var array
87+ */
88+ private $ genericMimeTypes = [
89+ 'application/x-empty ' ,
90+ 'inode/x-empty ' ,
91+ ];
92+
8193 /**
8294 * Get mime type of a file
8395 *
@@ -120,7 +132,11 @@ private function getNativeMimeType(string $file): string
120132 $ extension = $ this ->getFileExtension ($ file );
121133 $ result = mime_content_type ($ file );
122134 if (isset ($ this ->mimeTypes [$ extension ], $ this ->defineByExtensionList [$ extension ])
123- && (strpos ($ result , 'text/ ' ) === 0 || strpos ($ result , 'image/svg ' ) === 0 )
135+ && (
136+ strpos ($ result , 'text/ ' ) === 0
137+ || strpos ($ result , 'image/svg ' ) === 0
138+ || in_array ($ result , $ this ->genericMimeTypes , true )
139+ )
124140 ) {
125141 $ result = $ this ->mimeTypes [$ extension ];
126142 }
Original file line number Diff line number Diff line change 55 */
66namespace Magento \Framework \File \Test \Unit ;
77
8+ /**
9+ * Test mime type utility for correct
10+ */
811class MimeTest extends \PHPUnit \Framework \TestCase
912{
1013 /**
1114 * @var \Magento\Framework\File\Mime
1215 */
1316 private $ object ;
1417
18+ /**
19+ * @inheritDoc
20+ */
1521 protected function setUp ()
1622 {
1723 $ this ->object = new \Magento \Framework \File \Mime ();
@@ -42,12 +48,13 @@ public function testGetMimeType($file, $expectedType)
4248 /**
4349 * @return array
4450 */
45- public function getMimeTypeDataProvider ()
51+ public function getMimeTypeDataProvider (): array
4652 {
4753 return [
4854 'javascript ' => [__DIR__ . '/_files/javascript.js ' , 'application/javascript ' ],
4955 'weird extension ' => [__DIR__ . '/_files/file.weird ' , 'application/octet-stream ' ],
5056 'weird uppercase extension ' => [__DIR__ . '/_files/UPPERCASE.WEIRD ' , 'application/octet-stream ' ],
57+ 'generic mime type ' => [__DIR__ . '/_files/blank.html ' , 'text/html ' ],
5158 ];
5259 }
5360}
You can’t perform that action at this time.
0 commit comments