Skip to content

Commit e6e2b4e

Browse files
Merge branch '4.3' into 4.4
* 4.3: [Console] Constant STDOUT might be undefined. Allow returning null from NormalizerInterface::normalize [Security\Core] throw AccessDeniedException when switch user fails [Mime] fix guessing mime-types of files with leading dash [HttpFoundation] fix guessing mime-types of files with leading dash [VarExporter] fix exporting some strings [Cache] forbid serializing AbstractAdapter and TagAwareAdapter instances Use constant time comparison in UriSigner
2 parents 55b22cc + cabe672 commit e6e2b4e

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

File/MimeType/FileBinaryMimeTypeGuesser.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class FileBinaryMimeTypeGuesser implements MimeTypeGuesserInterface
3636
*
3737
* @param string $cmd The command to run to get the mime type of a file
3838
*/
39-
public function __construct(string $cmd = 'file -b --mime %s 2>/dev/null')
39+
public function __construct(string $cmd = 'file -b --mime -- %s 2>/dev/null')
4040
{
4141
$this->cmd = $cmd;
4242
}
@@ -85,7 +85,7 @@ public function guess($path)
8585
ob_start();
8686

8787
// need to use --mime instead of -i. see #6641
88-
passthru(sprintf($this->cmd, escapeshellarg($path)), $return);
88+
passthru(sprintf($this->cmd, escapeshellarg((0 === strpos($path, '-') ? './' : '').$path)), $return);
8989
if ($return > 0) {
9090
ob_end_clean();
9191

Tests/File/Fixtures/-test

35 Bytes
Binary file not shown.

Tests/File/MimeType/MimeTypeTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,17 @@
2121
*/
2222
class MimeTypeTest extends TestCase
2323
{
24+
public function testGuessWithLeadingDash()
25+
{
26+
$cwd = getcwd();
27+
chdir(__DIR__.'/../Fixtures');
28+
try {
29+
$this->assertEquals('image/gif', MimeTypeGuesser::getInstance()->guess('-test'));
30+
} finally {
31+
chdir($cwd);
32+
}
33+
}
34+
2435
public function testGuessImageWithoutExtension()
2536
{
2637
$this->assertEquals('image/gif', MimeTypeGuesser::getInstance()->guess(__DIR__.'/../Fixtures/test'));

0 commit comments

Comments
 (0)