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 /// Return the path of this file with the DAV part stripped
///
/// WebDAV file path: remote.php/dav/files/{username}/{strippedPath}
String get strippedPath { String get strippedPath {
// WebDAV path: remote.php/dav/files/{username}/{path}
if (path.contains("remote.php/dav/files")) { if (path.contains("remote.php/dav/files")) {
return path final position = path.indexOf("/", "remote.php/dav/files/".length) + 1;
.substring(path.indexOf("/", "remote.php/dav/files/".length) + 1); if (position == 0) {
// root dir path
return ".";
} else {
return path.substring(position);
}
} else { } else {
return path; return path;
} }

View file

@ -749,9 +749,16 @@ void main() {
}); });
}); });
test("strippedPath", () { group("strippedPath", () {
final file = File(path: "/remote.php/dav/files/admin/test.jpg"); test("file", () {
expect(file.strippedPath, "admin/test.jpg"); 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, ".");
});
}); });
}); });
} }