Skip to content
Permalink
Browse files

[HttpFoundation] fix guessing mime-types of files with leading dash

  • Loading branch information
nicolas-grekas committed Apr 19, 2019
1 parent 9fa32f4 commit 691486e43ce0e4893cd703e221bafc10a871f365
@@ -31,7 +31,7 @@ class FileBinaryMimeTypeGuesser implements MimeTypeGuesserInterface
*
* @param string $cmd The command to run to get the mime type of a file
*/
public function __construct(string $cmd = 'file -b --mime %s 2>/dev/null')
public function __construct(string $cmd = 'file -b --mime -- %s 2>/dev/null')
{
$this->cmd = $cmd;
}
@@ -80,7 +80,7 @@ public function guess($path)
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();

Binary file not shown.
@@ -20,7 +20,16 @@
*/
class MimeTypeTest extends TestCase
{
protected $path;
public function testGuessWithLeadingDash()
{
$cwd = getcwd();
chdir(__DIR__.'/../Fixtures');
try {
$this->assertEquals('image/gif', MimeTypeGuesser::getInstance()->guess('-test'));
} finally {
chdir($cwd);
}
}

public function testGuessImageWithoutExtension()
{

0 comments on commit 691486e

Please sign in to comment.
You can’t perform that action at this time.