From b17d9c9b51b040579c94aef22a6e4eca6e4a6c4e Mon Sep 17 00:00:00 2001 From: Veikka Tuominen Date: Sat, 14 Dec 2024 19:27:10 +0200 Subject: [PATCH] wrap paths containing terminal unsafe characters in quotes Closes #258 --- src/zigMainCodeLens.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/zigMainCodeLens.ts b/src/zigMainCodeLens.ts index e82b819..4943778 100644 --- a/src/zigMainCodeLens.ts +++ b/src/zigMainCodeLens.ts @@ -47,10 +47,17 @@ function zigRun() { terminal.show(); const wsFolder = getWorkspaceFolder(filePath); if (wsFolder && isWorkspaceFile(filePath) && hasBuildFile(wsFolder.uri.fsPath)) { - terminal.sendText(`${zigPath} build run`); + terminal.sendText(`${escapePath(zigPath)} build run`); return; } - terminal.sendText(`${zigPath} run "${filePath}"`); + terminal.sendText(`${escapePath(zigPath)} run ${escapePath(filePath)}`); +} + +function escapePath(rawPath: string): string { + if (/[ !"#$&'()*,;:<>?\[\\\]^`{|}]/.test(rawPath)) { + return `"${rawPath.replaceAll("\"", "\"\\\"\"")}"`; + } + return rawPath; } function hasBuildFile(workspaceFspath: string): boolean {