diff options
author | Robin Appelman <robin@icewind.nl> | 2017-01-23 21:45:16 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-23 21:45:16 +0100 |
commit | d4d116503cdb5538f544e47de9d2ec7d1698c8cd (patch) | |
tree | ce27568f5593eeee877ca4484d2ffb9b69c8d6f0 | |
parent | f19feccf9f71aae7261b9d796d30e497466c74e4 (diff) | |
parent | 3d99ec6832093652868f0dc0420d9d616f5e5310 (diff) | |
download | nextcloud-server-d4d116503cdb5538f544e47de9d2ec7d1698c8cd.tar.gz nextcloud-server-d4d116503cdb5538f544e47de9d2ec7d1698c8cd.zip |
Merge pull request #3212 from mwalbeck/mimetype-hidden-files
Mimetype detection for hidden files
-rw-r--r-- | lib/private/Files/Type/Detection.php | 4 | ||||
-rw-r--r-- | tests/lib/Files/Type/DetectionTest.php | 4 |
2 files changed, 8 insertions, 0 deletions
diff --git a/lib/private/Files/Type/Detection.php b/lib/private/Files/Type/Detection.php index 84d727ebb0e..cd4ddc2f067 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 87e0f94e3e2..5c1f48a806e 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('')); } |