Skip to content

Commit fc5171c

Browse files
authored
Ensure paths are always using forward slashes in terminal commands and args (#732)
* 🐛 fix #700
1 parent b3dd178 commit fc5171c

File tree

5 files changed

+10
-12
lines changed

5 files changed

+10
-12
lines changed

src/client/common/terminal/environmentActivationProviders/bash.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
import { inject, injectable } from 'inversify';
55
import { Uri } from 'vscode';
6-
import { PythonInterpreter } from '../../../interpreter/contracts';
76
import { IServiceContainer } from '../../../ioc/types';
87
import '../../extensions';
98
import { TerminalShellType } from '../types';
@@ -24,7 +23,7 @@ export class Bash extends BaseActivationCommandProvider {
2423
if (!scriptFile) {
2524
return;
2625
}
27-
return [`source ${scriptFile.toCommandArgument()}`];
26+
return [`source ${scriptFile.fileToCommandArgument()}`];
2827
}
2928

3029
private getScriptsInOrderOfPreference(targetShell: TerminalShellType): string[] {

src/client/common/terminal/environmentActivationProviders/commandPrompt.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import { inject, injectable } from 'inversify';
55
import * as path from 'path';
66
import { Uri } from 'vscode';
7-
import { PythonInterpreter } from '../../../interpreter/contracts';
87
import { IServiceContainer } from '../../../ioc/types';
98
import '../../extensions';
109
import { IPlatformService } from '../../platform/types';
@@ -29,9 +28,9 @@ export class CommandPromptAndPowerShell extends BaseActivationCommandProvider {
2928
}
3029

3130
if (targetShell === TerminalShellType.commandPrompt && scriptFile.endsWith('activate.bat')) {
32-
return [`${scriptFile.toCommandArgument()}`];
31+
return [scriptFile.fileToCommandArgument()];
3332
} else if ((targetShell === TerminalShellType.powershell || targetShell === TerminalShellType.powershellCore) && scriptFile.endsWith('activate.ps1')) {
34-
return [`& ${scriptFile.toCommandArgument()}`];
33+
return [`& ${scriptFile.fileToCommandArgument()}`];
3534
} else if (targetShell === TerminalShellType.commandPrompt && scriptFile.endsWith('activate.ps1')) {
3635
// lets not try to run the powershell file from command prompt (user may not have powershell)
3736
return [];
@@ -40,7 +39,7 @@ export class CommandPromptAndPowerShell extends BaseActivationCommandProvider {
4039
if (this.serviceContainer.get<IPlatformService>(IPlatformService).isWindows) {
4140
// On windows, the solution is to go into cmd, then run the batch (.bat) file and go back into powershell.
4241
const powershellExe = targetShell === TerminalShellType.powershell ? 'powershell' : 'pwsh';
43-
const activationCmd = `${scriptFile.toCommandArgument()}`;
42+
const activationCmd = scriptFile.fileToCommandArgument();
4443
return [
4544
`& cmd /k "${activationCmd} & ${powershellExe}"`
4645
];

src/client/terminals/codeExecution/terminalCodeExecution.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export class TerminalCodeExecutionProvider implements ICodeExecutionService {
8383
const fileDirPath = path.dirname(file.fsPath);
8484
const wkspace = this.workspace.getWorkspaceFolder(file);
8585
if (wkspace && fileDirPath !== wkspace.uri.fsPath && fileDirPath.length > 0) {
86-
await this.getTerminalService(file).sendText(`cd ${fileDirPath.toCommandArgument()}`);
86+
await this.getTerminalService(file).sendText(`cd ${fileDirPath.fileToCommandArgument()}`);
8787
}
8888
}
8989
}

src/test/terminals/codeExecution/djangoShellCodeExect.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ suite('Terminal - Django Shell Code Execution', () => {
115115
const workspaceUri = Uri.file(path.join('c', 'usr', 'program files'));
116116
const workspaceFolder: WorkspaceFolder = { index: 0, name: 'blah', uri: workspaceUri };
117117
workspace.setup(w => w.getWorkspaceFolder(TypeMoq.It.isAny())).returns(() => workspaceFolder);
118-
const expectedTerminalArgs = terminalArgs.concat(`"${path.join(workspaceUri.fsPath, 'manage.py')}"`, 'shell');
118+
const expectedTerminalArgs = terminalArgs.concat(`${path.join(workspaceUri.fsPath, 'manage.py').fileToCommandArgument()}`, 'shell');
119119

120120
testReplCommandArguments(true, pythonPath, pythonPath, terminalArgs, expectedTerminalArgs, Uri.file('x'));
121121
});
@@ -126,7 +126,7 @@ suite('Terminal - Django Shell Code Execution', () => {
126126
const workspaceUri = Uri.file(path.join('c', 'usr', 'programfiles'));
127127
const workspaceFolder: WorkspaceFolder = { index: 0, name: 'blah', uri: workspaceUri };
128128
workspace.setup(w => w.getWorkspaceFolder(TypeMoq.It.isAny())).returns(() => workspaceFolder);
129-
const expectedTerminalArgs = terminalArgs.concat(path.join(workspaceUri.fsPath, 'manage.py'), 'shell');
129+
const expectedTerminalArgs = terminalArgs.concat(path.join(workspaceUri.fsPath, 'manage.py').fileToCommandArgument(), 'shell');
130130

131131
testReplCommandArguments(true, pythonPath, pythonPath, terminalArgs, expectedTerminalArgs, Uri.file('x'));
132132
});
@@ -138,7 +138,7 @@ suite('Terminal - Django Shell Code Execution', () => {
138138
const workspaceFolder: WorkspaceFolder = { index: 0, name: 'blah', uri: workspaceUri };
139139
workspace.setup(w => w.getWorkspaceFolder(TypeMoq.It.isAny())).returns(() => undefined);
140140
workspace.setup(w => w.workspaceFolders).returns(() => [workspaceFolder]);
141-
const expectedTerminalArgs = terminalArgs.concat(`"${path.join(workspaceUri.fsPath, 'manage.py')}"`, 'shell');
141+
const expectedTerminalArgs = terminalArgs.concat(`${path.join(workspaceUri.fsPath, 'manage.py').fileToCommandArgument()}`, 'shell');
142142

143143
testReplCommandArguments(true, pythonPath, pythonPath, terminalArgs, expectedTerminalArgs, Uri.file('x'));
144144
});

src/test/terminals/codeExecution/terminalCodeExec.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ suite('Terminal Code Execution', () => {
135135

136136
await executor.executeFile(file);
137137

138-
terminalService.verify(async t => await t.sendText(TypeMoq.It.isValue(`cd ${path.dirname(file.fsPath)}`)), TypeMoq.Times.once());
138+
terminalService.verify(async t => await t.sendText(TypeMoq.It.isValue(`cd ${path.dirname(file.fsPath).fileToCommandArgument()}`)), TypeMoq.Times.once());
139139
}
140140
test('Ensure we set current directory before executing file (non windows)', async () => {
141141
await ensureWeSetCurrentDirectoryBeforeExecutingAFile(false);
@@ -154,7 +154,7 @@ suite('Terminal Code Execution', () => {
154154
terminalSettings.setup(t => t.launchArgs).returns(() => []);
155155

156156
await executor.executeFile(file);
157-
const dir = `"${path.dirname(file.fsPath)}"`.fileToCommandArgument();
157+
const dir = path.dirname(file.fsPath).fileToCommandArgument();
158158
terminalService.verify(async t => await t.sendText(TypeMoq.It.isValue(`cd ${dir}`)), TypeMoq.Times.once());
159159
}
160160

0 commit comments

Comments
 (0)