Merge pull request #3212 from mwalbeck/mimetype-hidden-files

Mimetype detection for hidden files
This commit is contained in:
Robin Appelman 2017-01-23 21:45:16 +01:00 committed by GitHub
commit d4d116503c
2 changed files with 8 additions and 0 deletions

View File

@ -167,6 +167,10 @@ class Detection implements IMimeTypeDetector {
$this->loadMappings();
$fileName = basename($path);
// remove leading dot on hidden files with a file extension
$fileName = ltrim($fileName, '.');
// note: leading dot doesn't qualify as extension
if (strpos($fileName, '.') > 0) {
//try to guess the type by the file extension

View File

@ -74,9 +74,13 @@ class DetectionTest extends \Test\TestCase {
$this->assertEquals('text/plain', $this->detection->detectPath('foo.txt'));
$this->assertEquals('image/png', $this->detection->detectPath('foo.png'));
$this->assertEquals('image/png', $this->detection->detectPath('foo.bar.png'));
$this->assertEquals('image/png', $this->detection->detectPath('.hidden.png'));
$this->assertEquals('image/png', $this->detection->detectPath('.hidden.foo.png'));
$this->assertEquals('image/png', $this->detection->detectPath('.hidden/foo.png'));
$this->assertEquals('image/png', $this->detection->detectPath('.hidden/.hidden.png'));
$this->assertEquals('image/png', $this->detection->detectPath('test.jpg/foo.png'));
$this->assertEquals('application/octet-stream', $this->detection->detectPath('.png'));
$this->assertEquals('application/octet-stream', $this->detection->detectPath('..hidden'));
$this->assertEquals('application/octet-stream', $this->detection->detectPath('foo'));
$this->assertEquals('application/octet-stream', $this->detection->detectPath(''));
}