From ed88b02deaab8e9bdd25e86bfc823916f5ac2b05 Mon Sep 17 00:00:00 2001 From: Charlie Egan Date: Mon, 14 Oct 2024 14:43:19 +0100 Subject: [PATCH] util: fix bug in replaceWorkspaceFolderPathVariable 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..8cf7618 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; }