Fix empty mime type filter

When the mime type is an empty array no filter should be applied.
However, the filter was loosely compared to an empty array, but as
arrays are objects then it became an implicit strict equality comparison
which always failed due to being different objects. Now the length of
the array is compared instead, and also moved outside the loop as it is
not needed to check it for each file.

Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
This commit is contained in:
Daniel Calviño Sánchez 2018-08-30 14:02:50 +02:00
parent 4508a12188
commit 66f2b155ce

View file

@ -841,9 +841,9 @@ var OCdialogs = {
filter = [filter];
}
self.filepicker.filesClient.getFolderContents(dir).then(function(status, files) {
if (filter) {
if (filter && filter.length > 0) {
files = files.filter(function (file) {
return filter == [] || file.type === 'dir' || filter.indexOf(file.mimetype) !== -1;
return file.type === 'dir' || filter.indexOf(file.mimetype) !== -1;
});
}
files = files.sort(function(a, b) {