Skip to content

Commit

Permalink
Merge branch '4.3' into 4.4
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
nicolas-grekas committed Nov 13, 2019
2 parents bf6913d + 22aecf6 commit 89da7b6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
4 changes: 2 additions & 2 deletions FileBinaryMimeTypeGuesser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -74,7 +74,7 @@ public function guessMimeType(string $path): ?string
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();

Expand Down
15 changes: 15 additions & 0 deletions Tests/AbstractMimeTypeGuesserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,21 @@ public static function tearDownAfterClass(): void

abstract protected function getGuesser(): MimeTypeGuesserInterface;

public function testGuessWithLeadingDash()
{
if (!$this->getGuesser()->isGuesserSupported()) {
$this->markTestSkipped('Guesser is not supported');
}

$cwd = getcwd();
chdir(__DIR__.'/Fixtures/mimetypes');
try {
$this->assertEquals('image/gif', $this->getGuesser()->guessMimeType('-test'));
} finally {
chdir($cwd);
}
}

public function testGuessImageWithoutExtension()
{
if (!$this->getGuesser()->isGuesserSupported()) {
Expand Down
Binary file added Tests/Fixtures/mimetypes/-test
Binary file not shown.

0 comments on commit 89da7b6

Please sign in to comment.