Skip to content

Commit

Permalink
util: fix bug in replaceWorkspaceFolderPathVariable (#288)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
charlieegan3 authored Oct 14, 2024
1 parent 5482a91 commit 68ce656
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit 68ce656

Please sign in to comment.