[HttpFoundation] fix guessing mime-types of files with leading dash
This commit is contained in:
parent
4463791d0e
commit
6be5cc75a4
@ -31,7 +31,7 @@ class FileBinaryMimeTypeGuesser implements MimeTypeGuesserInterface
|
|||||||
*
|
*
|
||||||
* @param string $cmd The command to run to get the mime type of a file
|
* @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;
|
$this->cmd = $cmd;
|
||||||
}
|
}
|
||||||
@ -80,7 +80,7 @@ class FileBinaryMimeTypeGuesser implements MimeTypeGuesserInterface
|
|||||||
ob_start();
|
ob_start();
|
||||||
|
|
||||||
// need to use --mime instead of -i. see #6641
|
// 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) {
|
if ($return > 0) {
|
||||||
ob_end_clean();
|
ob_end_clean();
|
||||||
|
|
||||||
|
BIN
src/Symfony/Component/HttpFoundation/Tests/File/Fixtures/-test
Normal file
BIN
src/Symfony/Component/HttpFoundation/Tests/File/Fixtures/-test
Normal file
Binary file not shown.
After Width: | Height: | Size: 35 B |
@ -20,7 +20,16 @@ use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesser;
|
|||||||
*/
|
*/
|
||||||
class MimeTypeTest extends TestCase
|
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()
|
public function testGuessImageWithoutExtension()
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user