fix(mount): stop double-encoding WebDAV paths

webdav lib encodePath already percent-encodes; our encodeURIComponent produced %25 and 400 on CJK/space paths.
This commit is contained in:
noelorin 2026-09-27 16:43:35 +08:00
parent a1483299f3
commit a7a50f8d0a
1 changed files with 7 additions and 4 deletions

View File

@ -231,10 +231,13 @@ function describeWebdavError(e: unknown, path?: string): string {
return `连接失败:${short}`;
}
/** WebDAV 路径:补前导 /、去重斜杠、段级百分号编码(中文/空格) */
/**
* WebDAV 路径:只做斜杠规范化。
* 不要 encodeURIComponent —— webdav 库内部 encodePath 会再编码一次,
* 双重编码(% → %25)会导致服务器 400 Bad Request。
*/
function normalizeWebdavPath(input: string): string {
const trimmed = input.trim() || "/";
const trimmed = (input || "/").trim().replace(/\\/g, "/");
const parts = trimmed.split("/").filter(Boolean);
const encoded = parts.map((seg) => encodeURIComponent(decodeURIComponent(seg)));
return `/${encoded.join("/")}`;
return parts.length ? `/${parts.join("/")}` : "/";
}