]> source.dussan.org Git - nextcloud-server.git/commitdiff
Fix mimetype filter in getDirectoryContent
authorRobin Appelman <icewind@owncloud.com>
Wed, 2 Dec 2015 15:48:15 +0000 (16:48 +0100)
committerRobin Appelman <icewind@owncloud.com>
Thu, 3 Dec 2015 12:09:13 +0000 (13:09 +0100)
lib/private/files/view.php
tests/lib/files/view.php

index 7854790d0e5f3fd16c3f05a76cf777bc1c6eaec8..6abefff4198ac67ae5fd90ed44856fc6110d1477 100644 (file)
@@ -1427,13 +1427,9 @@ class View {
                        if ($mimetype_filter) {
                                $files = array_filter($files, function (FileInfo $file) use ($mimetype_filter) {
                                        if (strpos($mimetype_filter, '/')) {
-                                               if ($file->getMimetype() === $mimetype_filter) {
-                                                       $result[] = $file;
-                                               }
+                                               return $file->getMimetype() === $mimetype_filter;
                                        } else {
-                                               if ($file->getMimePart() === $mimetype_filter) {
-                                                       $result[] = $file;
-                                               }
+                                               return $file->getMimePart() === $mimetype_filter;
                                        }
                                });
                        }
index 186cf28d7c3eb771209244dd474e7bcbe0faef0d..1fc4b9ab684600f1d5a01590b416eed081f09f49 100644 (file)
@@ -2389,4 +2389,39 @@ class View extends \Test\TestCase {
                $view = new \OC\Files\View('/' . $this->user . '/files');
                $this->assertEquals('foo', $view->rmdir('mount'));
        }
+
+       public function mimeFilterProvider() {
+               return [
+                       [null, ['test1.txt', 'test2.txt', 'test3.md', 'test4.png']],
+                       ['text/plain', ['test1.txt', 'test2.txt']],
+                       ['text/markdown', ['test3.md']],
+                       ['text', ['test1.txt', 'test2.txt', 'test3.md']],
+               ];
+       }
+
+       /**
+        * @param string $filter
+        * @param string[] $expected
+        * @dataProvider mimeFilterProvider
+        */
+       public function testGetDirectoryContentMimeFilter($filter, $expected) {
+               $storage1 = new Temporary();
+               $root = $this->getUniqueID('/');
+               \OC\Files\Filesystem::mount($storage1, array(), $root . '/');
+               $view = new \OC\Files\View($root);
+
+               $view->file_put_contents('test1.txt', 'asd');
+               $view->file_put_contents('test2.txt', 'asd');
+               $view->file_put_contents('test3.md', 'asd');
+               $view->file_put_contents('test4.png', '');
+
+               $content = $view->getDirectoryContent('', $filter);
+
+               $files = array_map(function(FileInfo $info) {
+                       return $info->getName();
+               }, $content);
+               sort($files);
+
+               $this->assertEquals($expected, $files);
+       }
 }