From ea05b7285766fbd24834b409f9f0328a9edda07d Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Thu, 13 Feb 2025 11:14:26 +0800 Subject: [PATCH] :bug: Fix local file open issue https://github.com/siyuan-note/siyuan/issues/14052 --- app/src/util/pathName.ts | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/app/src/util/pathName.ts b/app/src/util/pathName.ts index bd7b7b5e0..95eabaaa8 100644 --- a/app/src/util/pathName.ts +++ b/app/src/util/pathName.ts @@ -87,14 +87,22 @@ export const getAssetName = (assetPath: string) => { }; export const isLocalPath = (link: string) => { - link = link?.trim(); - if (!link || link.length === 0) { + if (!link) { return false; } - // Windows 网络共享路径双斜杠 - // 冒号前面只有一个字母认为是 Windows 盘符而不是网络协议 - return /^assets\/|file:\/\/|\\\\|[A-Z]:$/i.test(link); + 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 = () => {