Skip to content

Commit

Permalink
fix: quoted arguments with spaces are split
Browse files Browse the repository at this point in the history
Refs #28
  • Loading branch information
umbopepato committed May 29, 2020
1 parent 9d68205 commit c00c866
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
6 changes: 4 additions & 2 deletions 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,
Expand Down Expand Up @@ -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];
}
Expand Down
6 changes: 3 additions & 3 deletions src/util.ts
Expand Up @@ -2,9 +2,9 @@ export type OneOrMore<T> = 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,
);
}
Expand Down

0 comments on commit c00c866

Please sign in to comment.