Skip to content

Commit 35cd1d8

Browse files
committed
MC-31708: Magento Admin order creation Downloading Blank.html File
- Fix http response file content types should be determined based on file extension if the native mime type is generic (e.g application/octet-stream)
1 parent 852af4e commit 35cd1d8

File tree

4 files changed

+26
-2
lines changed

4 files changed

+26
-2
lines changed

dev/tests/static/testsuite/Magento/Test/Legacy/_files/copyright/blacklist.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@
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
];

lib/internal/Magento/Framework/File/Mime.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff 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
}

lib/internal/Magento/Framework/File/Test/Unit/MimeTest.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,19 @@
55
*/
66
namespace Magento\Framework\File\Test\Unit;
77

8+
/**
9+
* Test mime type utility for correct
10+
*/
811
class 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
}

lib/internal/Magento/Framework/File/Test/Unit/_files/blank.html

Whitespace-only changes.

0 commit comments

Comments
 (0)