Skip to content

Commit cd70a52

Browse files
juanmradnicolas-grekas
authored andcommitted
[MimeType] Duplicated MimeType due to PHP Bug
1 parent fbd216d commit cd70a52

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

File/MimeType/FileinfoMimeTypeGuesser.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,13 @@ public function guess($path)
6363
if (!$finfo = new \finfo(FILEINFO_MIME_TYPE, $this->magicFile)) {
6464
return null;
6565
}
66+
$mimeType = $finfo->file($path);
6667

67-
return $finfo->file($path);
68+
if ($mimeType && 0 === (\strlen($mimeType) % 2)) {
69+
$mimeStart = substr($mimeType, 0, \strlen($mimeType) >> 1);
70+
$mimeType = $mimeStart.$mimeStart === $mimeType ? $mimeStart : $mimeType;
71+
}
72+
73+
return $mimeType;
6874
}
6975
}

Tests/File/Fixtures/test.docx

5.92 KB
Binary file not shown.

Tests/File/MimeType/MimeTypeTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,14 @@ public function testGuessFileWithUnknownExtension()
6060
$this->assertEquals('application/octet-stream', MimeTypeGuesser::getInstance()->guess(__DIR__.'/../Fixtures/.unknownextension'));
6161
}
6262

63+
/**
64+
* @requires PHP 7.0
65+
*/
66+
public function testGuessWithDuplicatedFileType()
67+
{
68+
$this->assertEquals('application/vnd.openxmlformats-officedocument.wordprocessingml.document', MimeTypeGuesser::getInstance()->guess(__DIR__.'/../Fixtures/test.docx'));
69+
}
70+
6371
public function testGuessWithIncorrectPath()
6472
{
6573
$this->expectException('Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException');

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy