Skip to content

Commit 3f7cc13

Browse files
authored
Another attempt at doing things without a shell... (#3769)
1 parent 3e6f598 commit 3f7cc13

File tree

7 files changed

+16
-21
lines changed

7 files changed

+16
-21
lines changed

src/debugging/netcore/NetCoreDebugHelper.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import * as fse from 'fs-extra';
77
import * as path from 'path';
8-
import { CommandLineArgs, composeArgs, ContainerOS, innerQuoted, VoidCommandResponse, withArg } from '../../runtimes/docker';
8+
import { CommandLineArgs, composeArgs, ContainerOS, VoidCommandResponse, withArg, withQuotedArg } from '../../runtimes/docker';
99
import { DialogResponses, IActionContext, UserCancelledError } from '@microsoft/vscode-azext-utils';
1010
import { DebugConfiguration, MessageItem, ProgressLocation, window } from 'vscode';
1111
import { ext } from '../../extensionVariables';
@@ -312,13 +312,13 @@ export class NetCoreDebugHelper implements DebugHelper {
312312
containerCommand = 'cmd';
313313
containerCommandArgs = composeArgs(
314314
withArg('/C'),
315-
withArg(innerQuoted(`IF EXIST "${debuggerPath}" (exit 0) else (exit 1)`))
315+
withQuotedArg(`IF EXIST "${debuggerPath}" (exit 0) else (exit 1)`)
316316
)();
317317
} else {
318318
containerCommand = '/bin/sh';
319319
containerCommandArgs = composeArgs(
320320
withArg('-c'),
321-
withArg(innerQuoted(`if [ -f ${debuggerPath} ]; then exit 0; else exit 1; fi;`))
321+
withQuotedArg(`if [ -f ${debuggerPath} ]; then exit 0; else exit 1; fi;`)
322322
)();
323323
}
324324

src/runtimes/docker/clients/DockerClientBase/DockerClientBase.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import * as path from 'path';
77
import * as readline from 'readline';
8-
import type { ShellQuotedString } from 'vscode';
8+
import { ShellQuotedString, ShellQuoting } from 'vscode';
99
import { GeneratorCommandResponse, PromiseCommandResponse, VoidCommandResponse } from '../../contracts/CommandRunner';
1010
import {
1111
BuildImageCommandOptions,
@@ -76,7 +76,6 @@ import { CancellationError } from '../../utils/CancellationError';
7676
import {
7777
CommandLineArgs,
7878
composeArgs,
79-
innerQuoted,
8079
withArg,
8180
withFlagArg,
8281
withNamedArg,
@@ -1559,13 +1558,13 @@ export abstract class DockerClientBase extends ConfigurableClient implements ICo
15591558
'/C',
15601559
// Path is intentionally *not* quoted--no good quoting options work, but
15611560
// `cd` doesn't seem to care, so cd to the path and then do dir
1562-
innerQuoted(`cd ${options.path} & dir /A-S /-C`) as ShellQuotedString,
1561+
{ value: `cd ${options.path} & dir /A-S /-C`, quoting: ShellQuoting.Strong }
15631562
];
15641563
} else {
15651564
command = [
15661565
'/bin/sh',
15671566
'-c',
1568-
innerQuoted(`ls -lA '${options.path}'`) as ShellQuotedString,
1567+
{ value: `ls -lA "${options.path}"`, quoting: ShellQuoting.Strong }
15691568
];
15701569
}
15711570

@@ -1611,7 +1610,7 @@ export abstract class DockerClientBase extends ConfigurableClient implements ICo
16111610
const command = [
16121611
'cmd',
16131612
'/C',
1614-
innerQuoted(`cd ${folder} & type ${file}`) as ShellQuotedString,
1613+
{ value: `cd ${folder} & type ${file}`, quoting: ShellQuoting.Strong }
16151614
];
16161615

16171616
return this.getExecContainerCommandArgs(

src/runtimes/docker/clients/DockerClientBase/withDockerFilterArg.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import { ShellQuotedString } from 'vscode';
7-
import { CommandLineCurryFn, innerQuoted, withNamedArg } from '../../utils/commandLineBuilder';
7+
import { CommandLineCurryFn, withNamedArg } from '../../utils/commandLineBuilder';
88

9-
// The Docker CLI requires weak quoting of the --filter argument
109
export function withDockerFilterArg(filter: string | ShellQuotedString | (string | ShellQuotedString | null | undefined)[] | null | undefined): CommandLineCurryFn {
11-
return withNamedArg('--filter', Array.isArray(filter) ? filter.map(innerQuoted) : innerQuoted(filter));
10+
return withNamedArg('--filter', filter);
1211
}
1312

1413
export function withDockerBooleanFilterArg(filter: string, value: boolean | null | undefined): CommandLineCurryFn {

src/runtimes/docker/clients/DockerClientBase/withDockerJsonFormatArg.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
* Licensed under the MIT License. See LICENSE in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import { innerQuoted, withNamedArg } from '../../utils/commandLineBuilder';
6+
import { withNamedArg } from '../../utils/commandLineBuilder';
77

8-
// The Docker CLI requires weak quoting of the --format argument
9-
export const withDockerJsonFormatArg = withNamedArg('--format', innerQuoted('{{json .}}'));
8+
export const withDockerJsonFormatArg = withNamedArg('--format', '{{json .}}');

src/runtimes/docker/commandRunners/shellStream.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export class ShellStreamCommandRunnerFactory<TOptions extends ShellStreamCommand
5151
accumulator = new AccumulatorStream();
5252
}
5353

54-
await spawnStreamAsync(command, args, { ...this.options, stdOutPipe: accumulator, shell: true });
54+
await spawnStreamAsync(command, args, { ...this.options, stdOutPipe: accumulator });
5555

5656
throwIfCancellationRequested(this.options.cancellationToken);
5757

@@ -85,7 +85,7 @@ export class ShellStreamCommandRunnerFactory<TOptions extends ShellStreamCommand
8585
const innerGenerator = commandResponse.parseStream(dataStream, !!this.options.strict);
8686

8787
// The process promise will be awaited only after the innerGenerator finishes
88-
const processPromise = spawnStreamAsync(command, args, { ...this.options, stdOutPipe: dataStream, shell: true });
88+
const processPromise = spawnStreamAsync(command, args, { ...this.options, stdOutPipe: dataStream });
8989

9090
for await (const element of innerGenerator) {
9191
yield element;

src/runtimes/docker/utils/commandLineBuilder.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ type WithNamedArgOptions = {
9090
*/
9191
export function withNamedArg(
9292
name: string,
93-
args: Array<ShellQuotedString | string | undefined> | ShellQuotedString | string | null | undefined,
93+
args: Array<ShellQuotedString | string | null | undefined> | ShellQuotedString | string | null | undefined,
9494
{ assignValue = false, shouldQuote = true }: WithNamedArgOptions = {},
9595
): CommandLineCurryFn {
9696
return (cmdLineArgs: CommandLineArgs = []) => {

src/runtimes/docker/utils/spawnStreamAsync.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,8 @@ export async function spawnStreamAsync(
149149
// *nix
150150
const shell = options.shellProvider?.getShellOrDefault(options.shell) ?? options.shell;
151151

152-
// Apply quoting using the given shell provider or default
153-
// Because Docker is reparsing arguments containing spaces, the arguments *must* be quoted,
154-
// even though they are being supplied as whole strings without shell execution
155-
const normalizedArgs: string[] = Shell.getShellOrDefault(options.shellProvider).quote(args);
152+
// If there is a shell provider, apply its quoting, otherwise just flatten arguments into strings
153+
const normalizedArgs: string[] = options.shellProvider?.quote(args) ?? args.map(arg => typeof arg === 'string' ? arg : arg.value);
156154

157155
if (cancellationToken.isCancellationRequested) {
158156
throw new CancellationError('Command cancelled', cancellationToken);

0 commit comments

Comments
 (0)