Skip to content

Commit fb26f70

Browse files
Merge branch '3.4' into 4.4
* 3.4: [MimeType] Duplicated MimeType due to PHP Bug fix guessing form types for DateTime types fix handling typed properties as constraint options
2 parents cb769fd + b78af31 commit fb26f70

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

File/MimeType/FileinfoMimeTypeGuesser.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,13 @@ public function guess($path)
6868
if (!$finfo = new \finfo(FILEINFO_MIME_TYPE, $this->magicFile)) {
6969
return null;
7070
}
71+
$mimeType = $finfo->file($path);
7172

72-
return $finfo->file($path);
73+
if ($mimeType && 0 === (\strlen($mimeType) % 2)) {
74+
$mimeStart = substr($mimeType, 0, \strlen($mimeType) >> 1);
75+
$mimeType = $mimeStart.$mimeStart === $mimeType ? $mimeStart : $mimeType;
76+
}
77+
78+
return $mimeType;
7379
}
7480
}

Tests/File/Fixtures/test.docx

5.92 KB
Binary file not shown.

Tests/File/MimeType/MimeTypeTest.php

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

64+
public function testGuessWithDuplicatedFileType()
65+
{
66+
$this->assertEquals('application/vnd.openxmlformats-officedocument.wordprocessingml.document', MimeTypeGuesser::getInstance()->guess(__DIR__.'/../Fixtures/test.docx'));
67+
}
68+
6469
public function testGuessWithIncorrectPath()
6570
{
6671
$this->expectException('Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException');

0 commit comments

Comments
 (0)