Ensure File path not starting with /

This commit is contained in:
Ming Ming 2021-05-26 04:10:43 +08:00
parent 275603d88a
commit a429fbe006
2 changed files with 13 additions and 1 deletions

View file

@ -195,7 +195,7 @@ class File with EquatableMixin {
this.hasPreview, this.hasPreview,
this.fileId, this.fileId,
this.metadata, this.metadata,
}) : this.path = path.trimRightAny("/"); }) : this.path = path.trimAny("/");
factory File.fromJson(Map<String, dynamic> json) { factory File.fromJson(Map<String, dynamic> json) {
return File( return File(

View file

@ -327,6 +327,18 @@ void main() {
}); });
group("File", () { group("File", () {
group("constructor", () {
test("path trim slash", () {
final file = File(path: "/remote.php/dav/");
expect(file.path, "remote.php/dav");
});
test("path slash only", () {
final file = File(path: "/");
expect(file.path, "");
});
});
group("fromJson", () { group("fromJson", () {
test("path", () { test("path", () {
final json = <String, dynamic>{ final json = <String, dynamic>{