Fix folder name extraction functions

It should return empty string if there is no parent folder.
This commit is contained in:
Vladimir Golovnev (Glassez) 2020-12-17 21:23:31 +03:00 committed by sledgehammer999
commit dd3a8d5d56
No known key found for this signature in database
GPG key ID: 6E4A2D025B7CC9A2
2 changed files with 2 additions and 2 deletions

View file

@ -95,7 +95,7 @@ QString Utils::Fs::folderName(const QString &filePath)
const QString path = toUniformPath(filePath); const QString path = toUniformPath(filePath);
const int slashIndex = path.lastIndexOf('/'); const int slashIndex = path.lastIndexOf('/');
if (slashIndex == -1) if (slashIndex == -1)
return path; return {};
return path.left(slashIndex); return path.left(slashIndex);
} }

View file

@ -70,7 +70,7 @@ window.qBittorrent.Filesystem = (function() {
const folderName = function(filepath) { const folderName = function(filepath) {
const slashIndex = filepath.lastIndexOf(PathSeparator); const slashIndex = filepath.lastIndexOf(PathSeparator);
if (slashIndex === -1) if (slashIndex === -1)
return filepath; return '';
return filepath.substring(0, slashIndex); return filepath.substring(0, slashIndex);
}; };