diff --git a/lib/entity/file.dart b/lib/entity/file.dart index 9e3d4ff0..ba6ad1b0 100644 --- a/lib/entity/file.dart +++ b/lib/entity/file.dart @@ -302,11 +302,17 @@ class File with EquatableMixin { } /// Return the path of this file with the DAV part stripped + /// + /// WebDAV file path: remote.php/dav/files/{username}/{strippedPath} String get strippedPath { - // WebDAV path: remote.php/dav/files/{username}/{path} if (path.contains("remote.php/dav/files")) { - return path - .substring(path.indexOf("/", "remote.php/dav/files/".length) + 1); + final position = path.indexOf("/", "remote.php/dav/files/".length) + 1; + if (position == 0) { + // root dir path + return "."; + } else { + return path.substring(position); + } } else { return path; } diff --git a/test/entity/file_test.dart b/test/entity/file_test.dart index 33e0fc88..34eb4d98 100644 --- a/test/entity/file_test.dart +++ b/test/entity/file_test.dart @@ -749,9 +749,16 @@ void main() { }); }); - test("strippedPath", () { - final file = File(path: "/remote.php/dav/files/admin/test.jpg"); - expect(file.strippedPath, "admin/test.jpg"); + group("strippedPath", () { + test("file", () { + final file = File(path: "/remote.php/dav/files/admin/test.jpg"); + expect(file.strippedPath, "admin/test.jpg"); + }); + + test("root dir", () { + final file = File(path: "/remote.php/dav/files/admin"); + expect(file.strippedPath, "."); + }); }); }); }