Fix root dir path is not stripped correctly

This commit is contained in:
Ming Ming 2021-05-25 14:58:18 +08:00
parent 3c70d6f5e2
commit 72e6e7a9ec
2 changed files with 19 additions and 6 deletions

View file

@ -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;
}

View file

@ -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, ".");
});
});
});
}