From 4309f9def89c25611273d99db01e7cc477ad935e Mon Sep 17 00:00:00 2001 From: Nate Sesti Date: Mon, 4 Sep 2023 09:01:35 -0700 Subject: fix: :safety_vest: more safely convert windows path to posix --- extension/src/util/vscode.ts | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'extension/src/util') diff --git a/extension/src/util/vscode.ts b/extension/src/util/vscode.ts index 861ecd14..92bbc110 100644 --- a/extension/src/util/vscode.ts +++ b/extension/src/util/vscode.ts @@ -104,13 +104,23 @@ export function openEditorAndRevealRange( }); } +function windowsToPosix(windowsPath: string): string { + let posixPath = windowsPath.split("\\").join("/"); + if (posixPath[1] === ":") { + posixPath = posixPath.slice(2); + } + posixPath = posixPath.replace(" ", "\\ "); + return posixPath; +} + export function uriFromFilePath(filepath: string): vscode.Uri { if (vscode.env.remoteName) { if ( - vscode.env.remoteName === "wsl" || - vscode.env.remoteName === "ssh-remote" + (vscode.env.remoteName === "wsl" || + vscode.env.remoteName === "ssh-remote") && + process.platform === "win32" ) { - filepath = filepath.replace(/\\/g, "/"); + filepath = windowsToPosix(filepath); } return vscode.Uri.parse( `vscode-remote://${vscode.env.remoteName}${filepath}` -- cgit v1.2.3-70-g09d2