From: Nicolas Grekas <nicolas.grekas@gmail.com>
Date: Fri, 19 Apr 2019 14:48:43 +0200
Subject: [HttpFoundation] fix guessing mime-types of files with leading dash

https://github.com/symfony/symfony/commit/d41bd42ad5d51e0f4d24259ec2814ccb294c3ba2
---
 .../File/MimeType/FileBinaryMimeTypeGuesser.php            |   4 ++--
 .../Component/HttpFoundation/Tests/File/Fixtures/-test     | Bin 0 -> 35 bytes
 .../HttpFoundation/Tests/File/MimeType/MimeTypeTest.php    |  13 ++++++++++++-
 3 files changed, 14 insertions(+), 3 deletions(-)
 create mode 100644 src/Symfony/Component/HttpFoundation/Tests/File/Fixtures/-test

diff --git a/src/Symfony/Component/HttpFoundation/File/MimeType/FileBinaryMimeTypeGuesser.php b/src/Symfony/Component/HttpFoundation/File/MimeType/FileBinaryMimeTypeGuesser.php
index f917a06..2e9fce2 100644
--- a/src/Symfony/Component/HttpFoundation/File/MimeType/FileBinaryMimeTypeGuesser.php
+++ b/src/Symfony/Component/HttpFoundation/File/MimeType/FileBinaryMimeTypeGuesser.php
@@ -33,7 +33,7 @@ class FileBinaryMimeTypeGuesser implements MimeTypeGuesserInterface
      *
      * @param string $cmd The command to run to get the mime type of a file
      */
-    public function __construct($cmd = 'file -b --mime %s 2>/dev/null')
+    public function __construct($cmd = 'file -b --mime -- %s 2>/dev/null')
     {
         $this->cmd = $cmd;
     }
@@ -68,7 +68,7 @@ class FileBinaryMimeTypeGuesser implements MimeTypeGuesserInterface
         ob_start();
 
         // need to use --mime instead of -i. see #6641
-        passthru(sprintf($this->cmd, escapeshellarg($path)), $return);
+        passthru(sprintf($this->cmd, escapeshellarg((0 === strpos($path, '-') ? './' : '').$path)), $return);
         if ($return > 0) {
             ob_end_clean();
 
diff --git a/src/Symfony/Component/HttpFoundation/Tests/File/Fixtures/-test b/src/Symfony/Component/HttpFoundation/Tests/File/Fixtures/-test
new file mode 100644
index 0000000..b636f4b
--- /dev/null
+++ b/src/Symfony/Component/HttpFoundation/Tests/File/Fixtures/-test
@@ -0,0 +1 @@
+GIF87a  €  ÿÿÿÿÿÿ,       D ;
\ No newline at end of file
diff --git a/src/Symfony/Component/HttpFoundation/Tests/File/MimeType/MimeTypeTest.php b/src/Symfony/Component/HttpFoundation/Tests/File/MimeType/MimeTypeTest.php
index 1d5648e..41d859a 100644
--- a/src/Symfony/Component/HttpFoundation/Tests/File/MimeType/MimeTypeTest.php
+++ b/src/Symfony/Component/HttpFoundation/Tests/File/MimeType/MimeTypeTest.php
@@ -19,7 +19,18 @@ use Symfony\Component\HttpFoundation\File\MimeType\FileBinaryMimeTypeGuesser;
  */
 class MimeTypeTest extends \PHPUnit_Framework_TestCase
 {
-    protected $path;
+    public function testGuessWithLeadingDash()
+    {
+        $cwd = getcwd();
+        chdir(__DIR__.'/../Fixtures');
+        try {
+            $this->assertEquals('image/gif', MimeTypeGuesser::getInstance()->guess('-test'));
+            chdir($cwd);
+        } catch(\Exception $e) {
+            chdir($cwd);
+            throw $e;
+        }
+    }
 
     public function testGuessImageWithoutExtension()
     {
