]> source.dussan.org Git - nextcloud-server.git/commitdiff
[stable9.1] Fix mimetype detection inside hidden folders (#26138) (#26151) 1522/head
authorThomas Müller <DeepDiver1975@users.noreply.github.com>
Tue, 20 Sep 2016 09:16:44 +0000 (11:16 +0200)
committerLukas Reschke <lukas@statuscode.ch>
Mon, 26 Sep 2016 09:33:13 +0000 (11:33 +0200)
Downstreaming of https://github.com/owncloud/core/pull/26151

Signed-off-by: Lukas Reschke <lukas@statuscode.ch>
lib/private/Files/Type/Detection.php
tests/lib/Files/Type/DetectionTest.php

index 66ef0dd2aabfab71fbe44c6e7d2a1d367fd50392..84d727ebb0e9a8e21c97729eaa886053645aef3e 100644 (file)
@@ -166,9 +166,11 @@ class Detection implements IMimeTypeDetector {
        public function detectPath($path) {
                $this->loadMappings();
 
-               if (strpos($path, '.')) {
+               $fileName = basename($path);
+               // note: leading dot doesn't qualify as extension
+               if (strpos($fileName, '.') > 0) {
                        //try to guess the type by the file extension
-                       $extension = strtolower(strrchr(basename($path), "."));
+                       $extension = strtolower(strrchr($fileName, '.'));
                        $extension = substr($extension, 1); //remove leading .
                        return (isset($this->mimetypes[$extension]) && isset($this->mimetypes[$extension][0]))
                                ? $this->mimetypes[$extension][0]
index 11267ee2e7dfcef721575f3df6686ff89d0a535f..87e0f94e3e275debce87cc1b2e2faa77f620c8be 100644 (file)
@@ -74,6 +74,8 @@ 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/foo.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('foo'));
                $this->assertEquals('application/octet-stream', $this->detection->detectPath(''));