[MimeType] Duplicated MimeType due to PHP Bug
This commit is contained in:
parent
b30f4c1537
commit
7cb29c8b4b
@ -63,7 +63,13 @@ class FileinfoMimeTypeGuesser implements MimeTypeGuesserInterface
|
|||||||
if (!$finfo = new \finfo(FILEINFO_MIME_TYPE, $this->magicFile)) {
|
if (!$finfo = new \finfo(FILEINFO_MIME_TYPE, $this->magicFile)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
$mimeType = $finfo->file($path);
|
||||||
|
|
||||||
return $finfo->file($path);
|
if ($mimeType && 0 === (\strlen($mimeType) % 2)) {
|
||||||
|
$mimeStart = substr($mimeType, 0, \strlen($mimeType) >> 1);
|
||||||
|
$mimeType = $mimeStart.$mimeStart === $mimeType ? $mimeStart : $mimeType;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $mimeType;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Binary file not shown.
@ -60,6 +60,14 @@ class MimeTypeTest extends TestCase
|
|||||||
$this->assertEquals('application/octet-stream', MimeTypeGuesser::getInstance()->guess(__DIR__.'/../Fixtures/.unknownextension'));
|
$this->assertEquals('application/octet-stream', MimeTypeGuesser::getInstance()->guess(__DIR__.'/../Fixtures/.unknownextension'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @requires PHP 7.0
|
||||||
|
*/
|
||||||
|
public function testGuessWithDuplicatedFileType()
|
||||||
|
{
|
||||||
|
$this->assertEquals('application/vnd.openxmlformats-officedocument.wordprocessingml.document', MimeTypeGuesser::getInstance()->guess(__DIR__.'/../Fixtures/test.docx'));
|
||||||
|
}
|
||||||
|
|
||||||
public function testGuessWithIncorrectPath()
|
public function testGuessWithIncorrectPath()
|
||||||
{
|
{
|
||||||
$this->expectException('Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException');
|
$this->expectException('Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException');
|
||||||
|
Reference in New Issue
Block a user