Merge pull request #1522 from nextcloud/stable9.1-3f53730159d94bbc2b53129a4c750f5bab40a26e
[stable10] Fix mimetype detection inside hidden folders (#26138) (#2…
This commit is contained in:
commit
3e93dbd404
|
@ -166,9 +166,11 @@ class Detection implements IMimeTypeDetector {
|
||||||
public function detectPath($path) {
|
public function detectPath($path) {
|
||||||
$this->loadMappings();
|
$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
|
//try to guess the type by the file extension
|
||||||
$extension = strtolower(strrchr(basename($path), "."));
|
$extension = strtolower(strrchr($fileName, '.'));
|
||||||
$extension = substr($extension, 1); //remove leading .
|
$extension = substr($extension, 1); //remove leading .
|
||||||
return (isset($this->mimetypes[$extension]) && isset($this->mimetypes[$extension][0]))
|
return (isset($this->mimetypes[$extension]) && isset($this->mimetypes[$extension][0]))
|
||||||
? $this->mimetypes[$extension][0]
|
? $this->mimetypes[$extension][0]
|
||||||
|
|
|
@ -74,6 +74,8 @@ 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/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('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(''));
|
||||||
|
|
Loading…
Reference in New Issue