From fca4098facab3961e7f16e919b1a4f55c9a664bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Tue, 20 Sep 2016 11:16:44 +0200 Subject: [PATCH] [stable9.1] Fix mimetype detection inside hidden folders (#26138) (#26151) Downstreaming of https://github.com/owncloud/core/pull/26151 Signed-off-by: Lukas Reschke --- lib/private/Files/Type/Detection.php | 6 ++++-- tests/lib/Files/Type/DetectionTest.php | 2 ++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/private/Files/Type/Detection.php b/lib/private/Files/Type/Detection.php index 66ef0dd2aa..84d727ebb0 100644 --- a/lib/private/Files/Type/Detection.php +++ b/lib/private/Files/Type/Detection.php @@ -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] diff --git a/tests/lib/Files/Type/DetectionTest.php b/tests/lib/Files/Type/DetectionTest.php index 11267ee2e7..87e0f94e3e 100644 --- a/tests/lib/Files/Type/DetectionTest.php +++ b/tests/lib/Files/Type/DetectionTest.php @@ -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(''));