Skip to content

Commit

Permalink
Merge pull request #1522 from nextcloud/stable9.1-3f53730159d94bbc2b5…
Browse files Browse the repository at this point in the history
…3129a4c750f5bab40a26e

[stable10] Fix mimetype detection inside hidden folders (#26138) (#2
  • Loading branch information
MorrisJobke authored Sep 28, 2016
2 parents 7841f97 + fca4098 commit 3e93dbd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/private/Files/Type/Detection.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,11 @@ public function getAllMappings() {
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]
Expand Down
2 changes: 2 additions & 0 deletions tests/lib/Files/Type/DetectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ public function testDetectPath() {
$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(''));
Expand Down

0 comments on commit 3e93dbd

Please sign in to comment.