Skip to content

Commit 89da7b6

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 bf6913d + 22aecf6 commit 89da7b6

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

FileBinaryMimeTypeGuesser.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class FileBinaryMimeTypeGuesser implements MimeTypeGuesserInterface
3131
*
3232
* @param string $cmd The command to run to get the MIME type of a file
3333
*/
34-
public function __construct(string $cmd = 'file -b --mime %s 2>/dev/null')
34+
public function __construct(string $cmd = 'file -b --mime -- %s 2>/dev/null')
3535
{
3636
$this->cmd = $cmd;
3737
}
@@ -74,7 +74,7 @@ public function guessMimeType(string $path): ?string
7474
ob_start();
7575

7676
// need to use --mime instead of -i. see #6641
77-
passthru(sprintf($this->cmd, escapeshellarg($path)), $return);
77+
passthru(sprintf($this->cmd, escapeshellarg((0 === strpos($path, '-') ? './' : '').$path)), $return);
7878
if ($return > 0) {
7979
ob_end_clean();
8080

Tests/AbstractMimeTypeGuesserTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,21 @@ public static function tearDownAfterClass(): void
2727

2828
abstract protected function getGuesser(): MimeTypeGuesserInterface;
2929

30+
public function testGuessWithLeadingDash()
31+
{
32+
if (!$this->getGuesser()->isGuesserSupported()) {
33+
$this->markTestSkipped('Guesser is not supported');
34+
}
35+
36+
$cwd = getcwd();
37+
chdir(__DIR__.'/Fixtures/mimetypes');
38+
try {
39+
$this->assertEquals('image/gif', $this->getGuesser()->guessMimeType('-test'));
40+
} finally {
41+
chdir($cwd);
42+
}
43+
}
44+
3045
public function testGuessImageWithoutExtension()
3146
{
3247
if (!$this->getGuesser()->isGuesserSupported()) {

Tests/Fixtures/mimetypes/-test

35 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)