diff --git a/lib/private/Files/Type/Detection.php b/lib/private/Files/Type/Detection.php index 84d727ebb0e9a8e21c97729eaa886053645aef3e..cd4ddc2f06745313dce2c6360697410599d4ca7e 100644 --- a/lib/private/Files/Type/Detection.php +++ b/lib/private/Files/Type/Detection.php @@ -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 diff --git a/tests/lib/Files/Type/DetectionTest.php b/tests/lib/Files/Type/DetectionTest.php index 87e0f94e3e275debce87cc1b2e2faa77f620c8be..5c1f48a806e03e15dff6768cf3460664862a4245 100644 --- a/tests/lib/Files/Type/DetectionTest.php +++ b/tests/lib/Files/Type/DetectionTest.php @@ -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('')); }