diff --git a/src/main/server/file.ts b/src/main/server/file.ts index ffec94eeb..fab8d3e32 100644 --- a/src/main/server/file.ts +++ b/src/main/server/file.ts @@ -71,7 +71,9 @@ function getExcludeRegex () { } function withRepo (repo = 'main', callback: (repoPath: string, ...targetPath: string[]) => Promise, ...target: string[]): Promise { - const repoPath = repo.startsWith(ROOT_REPO_NAME_PREFIX) + const isRootRepo = repo.startsWith(ROOT_REPO_NAME_PREFIX) + + const repoPath = isRootRepo ? repo.substring(ROOT_REPO_NAME_PREFIX.length) : repository.getPath(repo) @@ -80,7 +82,9 @@ function withRepo (repo = 'main', callback: (repoPath: string, ...targetPath: } return callback(repoPath, ...target.map(x => { - const targetPath = path.join(repoPath, x) + const targetPath = isRootRepo + ? x.replace(/^\//, repoPath) // replace first / to repoPath for case of `\\127.0.0.1/test/a.md` + : path.join(repoPath, x) if (!targetPath.startsWith(repoPath)) { throw new Error('Path error.') diff --git a/src/renderer/services/document.ts b/src/renderer/services/document.ts index 61ce831b8..780e26fdb 100644 --- a/src/renderer/services/document.ts +++ b/src/renderer/services/document.ts @@ -887,7 +887,7 @@ export async function switchDocByPath (path: string): Promise { let root = '/' if (isWindows) { - const regMatch = path.match(/^([a-zA-Z]:\\)/) + const regMatch = path.match(/^([a-zA-Z]:\\|\\\\)/) if (regMatch) { root = regMatch[1] path = path.replace(root, '/')