Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[MimeType] Duplicated MimeType due to PHP Bug
  • Loading branch information
juanmrad authored and nicolas-grekas committed Jun 28, 2020
commit 7cb29c8b4b2990a2555d739ec11d7b9d0d46aff8
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,13 @@ public function guess($path)
if (!$finfo = new \finfo(FILEINFO_MIME_TYPE, $this->magicFile)) {
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.
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ public function testGuessFileWithUnknownExtension()
$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()
{
$this->expectException('Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException');
Expand Down