Skip to content

Commit

Permalink
Merge branch '3.4' into 4.4
Browse files Browse the repository at this point in the history
* 3.4:
  [MimeType] Duplicated MimeType due to PHP Bug
  fix guessing form types for DateTime types
  fix handling typed properties as constraint options
  • Loading branch information
nicolas-grekas committed Jun 28, 2020
2 parents cb769fd + b78af31 commit fb26f70
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
8 changes: 7 additions & 1 deletion File/MimeType/FileinfoMimeTypeGuesser.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,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 added Tests/File/Fixtures/test.docx
Binary file not shown.
5 changes: 5 additions & 0 deletions Tests/File/MimeType/MimeTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ public function testGuessFileWithUnknownExtension()
$this->assertEquals('application/octet-stream', MimeTypeGuesser::getInstance()->guess(__DIR__.'/../Fixtures/.unknownextension'));
}

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

0 comments on commit fb26f70

Please sign in to comment.