Skip to content

Commit bc75eb6

Browse files
committed
fix: return empty string for empty command arrays in getShellCommandAsString
1 parent f2c73f8 commit bc75eb6

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

src/features/terminal/shells/common/shellUtils.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ const shellDelimiterByShell = new Map<string, string>([
2424
]);
2525

2626
export function getShellCommandAsString(shell: string, command: PythonCommandRunConfiguration[]): string {
27+
// Return empty string for empty command arrays (e.g., when activation is intentionally skipped)
28+
if (command.length === 0) {
29+
return '';
30+
}
31+
2732
const delimiter = shellDelimiterByShell.get(shell) ?? defaultShellDelimiter;
2833
const parts = [];
2934
for (const cmd of command) {

src/test/features/terminal/shells/common/shellUtils.unit.test.ts

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,7 @@ suite('Shell Utils', () => {
9999
});
100100

101101
suite('getShellCommandAsString', () => {
102-
const sampleCommand: PythonCommandRunConfiguration[] = [
103-
{ executable: 'source', args: ['/path/to/activate'] },
104-
];
102+
const sampleCommand: PythonCommandRunConfiguration[] = [{ executable: 'source', args: ['/path/to/activate'] }];
105103

106104
suite('leading space for history ignore', () => {
107105
test('should add leading space for bash commands', () => {
@@ -184,5 +182,27 @@ suite('Shell Utils', () => {
184182
assert.ok(!result.startsWith(' '), 'Fish command should not start with a leading space');
185183
});
186184
});
185+
186+
suite('empty command handling', () => {
187+
test('should return empty string for empty command array (bash)', () => {
188+
const result = getShellCommandAsString(ShellConstants.BASH, []);
189+
assert.strictEqual(result, '', 'Empty command array should return empty string');
190+
});
191+
192+
test('should return empty string for empty command array (gitbash)', () => {
193+
const result = getShellCommandAsString(ShellConstants.GITBASH, []);
194+
assert.strictEqual(result, '', 'Empty command array should return empty string');
195+
});
196+
197+
test('should return empty string for empty command array (pwsh)', () => {
198+
const result = getShellCommandAsString(ShellConstants.PWSH, []);
199+
assert.strictEqual(result, '', 'Empty command array should return empty string');
200+
});
201+
202+
test('should return empty string for empty command array (cmd)', () => {
203+
const result = getShellCommandAsString(ShellConstants.CMD, []);
204+
assert.strictEqual(result, '', 'Empty command array should return empty string');
205+
});
206+
});
187207
});
188208
});

0 commit comments

Comments
 (0)