Skip to content
Snippets Groups Projects
Commit eadc1ac6 authored by Magnus Walbeck's avatar Magnus Walbeck
Browse files

Mimetype detection for hidden files


Signed-off-by: default avatarMagnus Walbeck <mw@mwalbeck.org>
parent 5d486478
No related branches found
No related tags found
No related merge requests found
...@@ -167,6 +167,12 @@ class Detection implements IMimeTypeDetector { ...@@ -167,6 +167,12 @@ class Detection implements IMimeTypeDetector {
$this->loadMappings(); $this->loadMappings();
$fileName = basename($path); $fileName = basename($path);
// remove leading dot on hidden files with a file extension
if (strpos($fileName, '.') === 0 && strpos($fileName, '.', 1)) {
$fileName = substr($fileName, 1);
}
// note: leading dot doesn't qualify as extension // note: leading dot doesn't qualify as extension
if (strpos($fileName, '.') > 0) { if (strpos($fileName, '.') > 0) {
//try to guess the type by the file extension //try to guess the type by the file extension
......
...@@ -74,9 +74,13 @@ class DetectionTest extends \Test\TestCase { ...@@ -74,9 +74,13 @@ class DetectionTest extends \Test\TestCase {
$this->assertEquals('text/plain', $this->detection->detectPath('foo.txt')); $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.png'));
$this->assertEquals('image/png', $this->detection->detectPath('foo.bar.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/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('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('.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('foo'));
$this->assertEquals('application/octet-stream', $this->detection->detectPath('')); $this->assertEquals('application/octet-stream', $this->detection->detectPath(''));
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment