Skip to content

Commit 1c15d37

Browse files
committed
use quoteArg
1 parent bf283f0 commit 1c15d37

2 files changed

Lines changed: 6 additions & 10 deletions

File tree

src/features/execution/execUtils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function quoteArg(arg: string): string {
1+
export function quoteArg(arg: string): string {
22
if (arg.indexOf(' ') >= 0 && !(arg.startsWith('"') && arg.endsWith('"'))) {
33
return `"${arg}"`;
44
}

src/features/execution/runAsTask.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ import {
88
Uri,
99
WorkspaceFolder,
1010
} from 'vscode';
11-
import { PythonTaskExecutionOptions } from '../../api';
12-
import { getWorkspaceFolder } from '../../common/workspace.apis';
13-
import { PythonEnvironment } from '../../api';
11+
import { PythonEnvironment, PythonTaskExecutionOptions } from '../../api';
1412
import { executeTask } from '../../common/tasks.apis';
13+
import { getWorkspaceFolder } from '../../common/workspace.apis';
14+
import { quoteArg } from './execUtils';
1515

1616
function getWorkspaceFolderOrDefault(uri?: Uri): WorkspaceFolder | TaskScope {
1717
const workspace = uri ? getWorkspaceFolder(uri) : undefined;
@@ -25,12 +25,8 @@ export async function runAsTask(
2525
): Promise<TaskExecution> {
2626
const workspace: WorkspaceFolder | TaskScope = getWorkspaceFolderOrDefault(options.project?.uri);
2727

28-
let executable =
29-
environment.execInfo?.activatedRun?.executable ?? environment.execInfo?.run.executable ?? 'python';
30-
// Quote the executable if it contains spaces and is not already quoted
31-
if (executable.includes(' ') && !(executable.startsWith('"') && executable.endsWith('"'))) {
32-
executable = `"${executable}"`;
33-
}
28+
let executable = environment.execInfo?.activatedRun?.executable ?? environment.execInfo?.run.executable ?? 'python';
29+
quoteArg(executable);
3430
const args = environment.execInfo?.activatedRun?.args ?? environment.execInfo?.run.args ?? [];
3531
const allArgs = [...args, ...options.args];
3632

0 commit comments

Comments
 (0)