Skip to content

Commit 16dd726

Browse files
Merge pull request #3 from relution-io/feature/REL-5239_use_displayname
REL-5239: extract displayname
2 parents cbbc737 + d67d6c0 commit 16dd726

File tree

1 file changed

+29
-4
lines changed

1 file changed

+29
-4
lines changed

lib/src/xml.dart

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,35 @@ class WebdavXml {
103103
mTime = null;
104104
}
105105

106-
//
107-
var str = Uri.decodeFull(href);
108-
var name = path2Name(str);
109-
var filePath = path + name + (isDir ? '/' : '');
106+
// displayname
107+
final displayNameElements = findElements(prop, 'displayname');
108+
String? displayName = displayNameElements.isNotEmpty
109+
? displayNameElements.single.text
110+
: null;
111+
112+
// Try to parse href to Uri. Use encoded version of hrefas fallback
113+
// so filename with special characters wont lead to crash
114+
var hrefAsUri =
115+
Uri.tryParse(href) ?? Uri.tryParse(Uri.encodeFull(href));
116+
117+
String pathElementName;
118+
String name;
119+
// use manual path splitting as fallback
120+
if (hrefAsUri != null) {
121+
pathElementName = hrefAsUri.pathSegments.lastWhere(
122+
(element) => element != "",
123+
orElse: () => path2Name(href),
124+
);
125+
} else {
126+
pathElementName = path2Name(href);
127+
}
128+
129+
// some WebDav serve provides a custom name for path, if not use jsut the path name
130+
name = displayName ?? pathElementName;
131+
// uri.pathSegments will be decoded so we need to encode it back to sue
132+
// it as path for further requests
133+
var filePath =
134+
path + Uri.encodeFull(pathElementName) + (isDir ? '/' : '');
110135

111136
files.add(File(
112137
path: filePath,

0 commit comments

Comments
 (0)