diff options
author | Nate Sesti <sestinj@gmail.com> | 2023-09-04 09:01:35 -0700 |
---|---|---|
committer | Nate Sesti <sestinj@gmail.com> | 2023-09-04 09:01:35 -0700 |
commit | 4309f9def89c25611273d99db01e7cc477ad935e (patch) | |
tree | 007a284521b16083a037996245233ff3f4c573e0 /extension/src/util/vscode.ts | |
parent | faaf1b9402b887bf1f68b1a0152e07b86b6cfa30 (diff) | |
download | sncontinue-4309f9def89c25611273d99db01e7cc477ad935e.tar.gz sncontinue-4309f9def89c25611273d99db01e7cc477ad935e.tar.bz2 sncontinue-4309f9def89c25611273d99db01e7cc477ad935e.zip |
fix: :safety_vest: more safely convert windows path to posix
Diffstat (limited to 'extension/src/util/vscode.ts')
-rw-r--r-- | extension/src/util/vscode.ts | 16 |
1 files changed, 13 insertions, 3 deletions
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}` |