Skip to content

Commit fe5027c

Browse files
committed
Add tests for TerminalPanel.preparePathForTerminal
Fixes microsoft#27771
1 parent 5a40dc5 commit fe5027c

2 files changed

Lines changed: 24 additions & 2 deletions

File tree

src/vs/workbench/parts/terminal/electron-browser/terminalPanel.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ export class TerminalPanel extends Panel {
246246
}
247247

248248
const terminal = this._terminalService.getActiveInstance();
249-
terminal.sendText(this._preparePathForTerminal(uri), false);
249+
terminal.sendText(TerminalPanel.preparePathForTerminal(uri), false);
250250
}
251251
}));
252252
}
@@ -327,7 +327,7 @@ export class TerminalPanel extends Panel {
327327
/**
328328
* Adds quotes to a path if it contains whitespaces
329329
*/
330-
private _preparePathForTerminal(path: string) {
330+
public static preparePathForTerminal(path: string): string {
331331
if (platform.isWindows) {
332332
if (/\s+/.test(path)) {
333333
return `"${path}"`;
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
'use strict';
7+
8+
import * as assert from 'assert';
9+
import { TerminalPanel } from 'vs/workbench/parts/terminal/electron-browser/terminalPanel';
10+
import * as platform from 'vs/base/common/platform';
11+
12+
suite('Workbench - TerminalPanel', () => {
13+
test('preparePathForTerminal', function () {
14+
if (platform.isWindows) {
15+
assert.equal(TerminalPanel.preparePathForTerminal('C:\\foo'), 'C:\\foo');
16+
assert.equal(TerminalPanel.preparePathForTerminal('C:\\foo bar'), '"C:\\foo bar"');
17+
return;
18+
}
19+
assert.equal(TerminalPanel.preparePathForTerminal('/a/\\foo bar"\'? ;\'?? :'), '/a/\\\\foo\\ bar\\"\\\'\\?\\ \\;\\\'\\?\\?\\ \\ \\:');
20+
assert.equal(TerminalPanel.preparePathForTerminal('/\\\'"?:;!*(){}[]'), '/\\\\\\\'\\"\\?\\:\\;\\!\\*\\(\\)\\{\\}\\[\\]');
21+
});
22+
});

0 commit comments

Comments
 (0)