diff --git a/src/run_commands.ts b/src/run_commands.ts index 42ad882..a8d8368 100644 --- a/src/run_commands.ts +++ b/src/run_commands.ts @@ -1,4 +1,4 @@ -import { isWindows, OneOrMore } from "./util.ts"; +import { isWindows, OneOrMore, escape } from "./util.ts"; import { log } from "./logger.ts"; import { EnvironmentVariables, @@ -89,7 +89,9 @@ function buildShellArgs( ): string[] { const fullCmd = additionalArgs.length < 1 ? command - : `${command} ${additionalArgs.join(" ")}`; + : `${command} ${ + additionalArgs.map((a) => `"${escape(a, '"')}"`).join(" ") + }`; if (isWindows && /^(?:.*\\)?cmd(?:\.exe)?$/i.test(shell)) { return ["/d", "/s", "/c", fullCmd]; } diff --git a/src/util.ts b/src/util.ts index a5370da..2c4b549 100644 --- a/src/util.ts +++ b/src/util.ts @@ -2,9 +2,9 @@ export type OneOrMore = T | T[]; export const isWindows = Deno.build.os == "windows"; -export function escape(str: string, ...chars: string[]): string { - return chars.reduce( - (str, char) => str.replace(RegExp(char, "g"), `\\${char}`), +export function escape(str: string, ...exp: string[]): string { + return exp.reduce( + (str, e) => str.replace(RegExp(e, "g"), `\\${e}`), str, ); }