diff --git a/app/src/editor/util.ts b/app/src/editor/util.ts index 51b44fd8c..6a5c09936 100644 --- a/app/src/editor/util.ts +++ b/app/src/editor/util.ts @@ -472,7 +472,7 @@ export const openBy = (url: string, type: "folder" | "app") => { let address = ""; if ("windows" === window.siyuan.config.system.os) { // `file://` 协议兼容 Window 平台使用 `/` 作为目录分割线 https://github.com/siyuan-note/siyuan/issues/5681 - address = url.replace("file:///", "").replace("file://\\", "").replace("file://", "").replace("/", "\\"); + address = url.replace("file:///", "").replace("file://\\", "").replace("file://", "").replace(/\//g, "\\"); } else { address = url.replace("file://", ""); } @@ -482,8 +482,10 @@ export const openBy = (url: string, type: "folder" | "app") => { shell.openPath(address); } else if (type === "folder") { if ("windows" === window.siyuan.config.system.os) { - // Windows 端打开本地文件所在位置失效 https://github.com/siyuan-note/siyuan/issues/5808 - address = address.replace(/\\\\/g, "\\"); + if (!address.startsWith("\\\\")) { // \\ 开头的路径是 Windows 网络共享路径 https://github.com/siyuan-note/siyuan/issues/5980 + // Windows 端打开本地文件所在位置失效 https://github.com/siyuan-note/siyuan/issues/5808 + address = address.replace(/\\\\/g, "\\"); + } } shell.showItemInFolder(address); } diff --git a/app/src/util/pathName.ts b/app/src/util/pathName.ts index 5e0aaaf9d..758744728 100644 --- a/app/src/util/pathName.ts +++ b/app/src/util/pathName.ts @@ -37,8 +37,19 @@ export const isLocalPath = (link: string) => { if (!link) { return false; } - return link.startsWith("assets/") || link.startsWith("file://") || - 0 < link.indexOf(":/") || link.startsWith("\\\\"); // 超链接地址更好地兼容本地路径 https://github.com/siyuan-note/siyuan/issues/5980 + + link = link.trim() + if (1 > link.length) { + return false; + } + + link = link.toLowerCase() + if (link.startsWith("assets/") || link.startsWith("file://") || link.startsWith("\\\\") /* Windows 网络共享路径 */) { + return true + } + + const colonIdx = link.indexOf(":") + return 1 === colonIdx // 冒号前面只有一个字符认为是 Windows 盘符而不是网络协议 }; export const pathPosix = () => { diff --git a/kernel/model/upload.go b/kernel/model/upload.go index 12ffb93a4..5c2c4f3d0 100644 --- a/kernel/model/upload.go +++ b/kernel/model/upload.go @@ -60,7 +60,10 @@ func InsertLocalAssets(id string, assetPaths []string, isUpload bool) (succMap m fName += ext baseName := fName if gulu.File.IsDir(p) || !isUpload { - succMap[baseName] = "file://" + p + if !strings.HasPrefix(p, "\\\\") { + p = "file://" + p + } + succMap[baseName] = p continue }