Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 6ef3fee

Browse filesBrowse files
bug #37291 [MimeType] Duplicated MimeType due to PHP Bug (juanmrad)
This PR was squashed before being merged into the 3.4 branch. Discussion ---------- [MimeType] Duplicated MimeType due to PHP Bug | Q | A | ------------- | --- | Branch? | 5.1 | Bug fix? | yes | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tickets | Fix #... <!-- prefix each issue number with "Fix #", if any --> | License | MIT | Doc PR | symfony/symfony-docs#... <!-- required for new features --> ## Issue: Currently there is a PHP bug https://bugs.php.net/bug.php?id=77784 that is causing several MimeTypes to be given as duplicated: ``` application/vnd.openxmlformats-officedocument.spreadsheetml.sheetapplication/vnd.openxmlformats-officedocument.spreadsheetml.sheet ``` Instead of: ``` application/vnd.openxmlformats-officedocument.spreadsheetml.sheet ``` This Patch will fix the Issues by checking if a returned MimeType is duplicated and return appropriate MimeType. This patch should be reverted if the PHP Bug is ever fixed. Commits ------- 7cb29c8 [MimeType] Duplicated MimeType due to PHP Bug
2 parents 9566cff + 7cb29c8 commit 6ef3fee
Copy full SHA for 6ef3fee

File tree

3 files changed

+15
-1
lines changed
Filter options

3 files changed

+15
-1
lines changed

‎src/Symfony/Component/HttpFoundation/File/MimeType/FileinfoMimeTypeGuesser.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/File/MimeType/FileinfoMimeTypeGuesser.php
+7-1Lines 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
}
Binary file not shown.

‎src/Symfony/Component/HttpFoundation/Tests/File/MimeType/MimeTypeTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/Tests/File/MimeType/MimeTypeTest.php
+8Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.