diff --git a/src/windowsPtyAgent.test.ts b/src/windowsPtyAgent.test.ts index 3a80d64b8..a4a065768 100644 --- a/src/windowsPtyAgent.test.ts +++ b/src/windowsPtyAgent.test.ts @@ -64,10 +64,10 @@ if (process.platform === 'win32') { check('asdf', ['quotes "in the" middle'], 'asdf "quotes \\"in the\\" middle"'); }); it('array argument quotes near start', () => { - check('asdf', ['"quotes" near start'], 'asdf \\"quotes\\" near start'); + check('asdf', ['"quotes" near start'], 'asdf "\\"quotes\\" near start"'); }); it('array argument quotes near end', () => { - check('asdf', ['quotes "near end"'], 'asdf quotes \\"near end\\"'); + check('asdf', ['quotes "near end"'], 'asdf "quotes \\"near end\\""'); }); }); diff --git a/src/windowsPtyAgent.ts b/src/windowsPtyAgent.ts index a94454860..2db771357 100644 --- a/src/windowsPtyAgent.ts +++ b/src/windowsPtyAgent.ts @@ -129,13 +129,14 @@ export function argsToCommandLine(file: string, args: ArgvOrCommandLine): string } const arg = argv[argIndex]; // if it is empty or it contains whitespace and is not already quoted + const hasLopsidedEnclosingQuote = xOr((arg[0] !== '"'), (arg[arg.length - 1] !== '"')); + const hasNoEnclosingQuotes = ((arg[0] !== '"') && (arg[arg.length - 1] !== '"')); const quote = arg === '' || (arg.indexOf(' ') !== -1 || arg.indexOf('\t') !== -1) && ((arg.length > 1) && - ((arg[0] !== '"') && - (arg[arg.length - 1] !== '"'))); + (hasLopsidedEnclosingQuote || hasNoEnclosingQuotes)); if (quote) { result += '\"'; } @@ -175,3 +176,7 @@ function repeatText(text: string, count: number): string { } return result; } + +function xOr(arg1: boolean, arg2: boolean): boolean { + return ((arg1 && !arg2) || (!arg1 && arg2)); +}