From 68ce656187198eaf2f6ae2a711f9017abf2b8b37 Mon Sep 17 00:00:00 2001 From: Charlie Egan Date: Mon, 14 Oct 2024 15:28:03 +0100 Subject: [PATCH] util: fix bug in replaceWorkspaceFolderPathVariable (#288) replaceWorkspaceFolderPathVariable's previous implementation would use partially %-encoded paths in the replacement string. This would cause an issue on windows hosts where the files would not be readable at these incorrect paths. Signed-off-by: Charlie Egan --- src/util.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/util.ts b/src/util.ts index 495f1ec..3f60d67 100644 --- a/src/util.ts +++ b/src/util.ts @@ -51,10 +51,15 @@ export function getPrettyTime(ns: number): string { export function replaceWorkspaceFolderPathVariable(path: string): string { if (vscode.workspace.workspaceFolders !== undefined) { - path = path.replace("${workspaceFolder}", vscode.workspace.workspaceFolders![0].uri.toString()); - path = path.replace("${workspacePath}", vscode.workspace.workspaceFolders![0].uri.path); + // here, uri.fsPath is used as this returns a usable path on both Windows and Unix + const workspaceFolderPath = vscode.workspace.workspaceFolders![0].uri.fsPath; + path = path.replace("${workspaceFolder}", workspaceFolderPath); + path = path.replace("${workspacePath}", workspaceFolderPath); } else if (path.indexOf("${workspaceFolder}") >= 0) { - vscode.window.showWarningMessage("${workspaceFolder} variable configured in settings, but no workspace is active"); + vscode.window.showWarningMessage( + "${workspaceFolder} variable configured in settings, but no workspace is active", + ); } + return path; }