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 10
10
'/setup\/src\/Zend\/Mvc\/Controller\/LazyControllerAbstractFactory\.php/ ' ,
11
11
'/app\/code\/(?!Magento)[^\/]*/ ' ,
12
12
'#dev/tests/setup-integration/testsuite/Magento/Developer/_files/\S*\.xml$# ' ,
13
+ '/lib\/internal\/Magento\/Framework\/File\/Test\/Unit\/_files\/blank.html$/ '
13
14
];
Original file line number Diff line number Diff line change @@ -78,6 +78,18 @@ class Mime
78
78
'svg ' => 'image/svg+xml ' ,
79
79
];
80
80
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
+
81
93
/**
82
94
* Get mime type of a file
83
95
*
@@ -120,7 +132,11 @@ private function getNativeMimeType(string $file): string
120
132
$ extension = $ this ->getFileExtension ($ file );
121
133
$ result = mime_content_type ($ file );
122
134
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
+ )
124
140
) {
125
141
$ result = $ this ->mimeTypes [$ extension ];
126
142
}
Original file line number Diff line number Diff line change 5
5
*/
6
6
namespace Magento \Framework \File \Test \Unit ;
7
7
8
+ /**
9
+ * Test mime type utility for correct
10
+ */
8
11
class MimeTest extends \PHPUnit \Framework \TestCase
9
12
{
10
13
/**
11
14
* @var \Magento\Framework\File\Mime
12
15
*/
13
16
private $ object ;
14
17
18
+ /**
19
+ * @inheritDoc
20
+ */
15
21
protected function setUp ()
16
22
{
17
23
$ this ->object = new \Magento \Framework \File \Mime ();
@@ -42,12 +48,13 @@ public function testGetMimeType($file, $expectedType)
42
48
/**
43
49
* @return array
44
50
*/
45
- public function getMimeTypeDataProvider ()
51
+ public function getMimeTypeDataProvider (): array
46
52
{
47
53
return [
48
54
'javascript ' => [__DIR__ . '/_files/javascript.js ' , 'application/javascript ' ],
49
55
'weird extension ' => [__DIR__ . '/_files/file.weird ' , 'application/octet-stream ' ],
50
56
'weird uppercase extension ' => [__DIR__ . '/_files/UPPERCASE.WEIRD ' , 'application/octet-stream ' ],
57
+ 'generic mime type ' => [__DIR__ . '/_files/blank.html ' , 'text/html ' ],
51
58
];
52
59
}
53
60
}
You can’t perform that action at this time.
0 commit comments