Skip to content

Commit

Permalink
[stable9.1] Fix mimetype detection inside hidden folders (#26138) (#2…
Browse files Browse the repository at this point in the history
…6151)

Downstreaming of owncloud/core#26151

Signed-off-by: Lukas Reschke <lukas@statuscode.ch>
  • Loading branch information
DeepDiver1975 authored and LukasReschke committed Sep 26, 2016
1 parent e0dd676 commit fca4098
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 fca4098

Please sign in to comment.