Skip to content

Commit 06f0e55

Browse files
committed
fix: remove trailing slash from file paths in PROPFIND requests.Synology WebDAV requires file paths without trailing slashes to avoid 400 errors.
修复:PROPFIND请求如果是文件则不要增加尾 '/',群晖不支持,会返回400请求
1 parent 5a8dd0d commit 06f0e55

2 files changed

Lines changed: 12 additions & 4 deletions

File tree

lib/src/client.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,10 @@ class Client {
7272
}
7373

7474
/// Read a single files properties
75-
Future<File> readProps(String path, [CancelToken? cancelToken]) async {
76-
path = fixSlashes(path);
75+
Future<File> readProps(String path,{ bool isFile = false, CancelToken? cancelToken}) async {
76+
//如果是文件,不要添加尾 '/', 因为一些服务器可能不支持文件带 尾 '/' 的props请求,例如群晖
77+
//If it is a file, do not add a trailing '/', because some servers (such as Synology) may not support PROPFIND requests for files with a trailing '/'.
78+
path = isFile ? fixSlashStart(path) : fixSlashes(path);
7779
var resp = await this
7880
.c
7981
.wdPropfind(this, path, true, fileXmlStr, cancelToken: cancelToken);

lib/src/utils.dart

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,17 @@ String fixSlash(String s) {
102102
return s;
103103
}
104104

105-
// 添加 '/' 前后缀
106-
String fixSlashes(String s) {
105+
//添加 '/' 前缀
106+
String fixSlashStart(String s){
107107
if (!s.startsWith('/')) {
108108
s = '/${s}';
109109
}
110+
return s;
111+
}
112+
113+
// 添加 '/' 前后缀
114+
String fixSlashes(String s) {
115+
s = fixSlashStart(s);
110116
return fixSlash(s);
111117
}
112118

0 commit comments

Comments
 (0)