diff --git a/src/vs/workbench/parts/terminal/electron-browser/terminalPanel.ts b/src/vs/workbench/parts/terminal/electron-browser/terminalPanel.ts index bec620085a159..b9c0c7282937c 100644 --- a/src/vs/workbench/parts/terminal/electron-browser/terminalPanel.ts +++ b/src/vs/workbench/parts/terminal/electron-browser/terminalPanel.ts @@ -246,7 +246,7 @@ export class TerminalPanel extends Panel { } const terminal = this._terminalService.getActiveInstance(); - terminal.sendText(this._preparePathForTerminal(uri), false); + terminal.sendText(TerminalPanel.preparePathForTerminal(uri), false); } })); } @@ -327,7 +327,7 @@ export class TerminalPanel extends Panel { /** * Adds quotes to a path if it contains whitespaces */ - private _preparePathForTerminal(path: string) { + public static preparePathForTerminal(path: string): string { if (platform.isWindows) { if (/\s+/.test(path)) { return `"${path}"`; diff --git a/src/vs/workbench/parts/terminal/test/electron-browser/terminalPanel.test.ts b/src/vs/workbench/parts/terminal/test/electron-browser/terminalPanel.test.ts new file mode 100644 index 0000000000000..20ca2648f1b6d --- /dev/null +++ b/src/vs/workbench/parts/terminal/test/electron-browser/terminalPanel.test.ts @@ -0,0 +1,22 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +'use strict'; + +import * as assert from 'assert'; +import { TerminalPanel } from 'vs/workbench/parts/terminal/electron-browser/terminalPanel'; +import * as platform from 'vs/base/common/platform'; + +suite('Workbench - TerminalPanel', () => { + test('preparePathForTerminal', function () { + if (platform.isWindows) { + assert.equal(TerminalPanel.preparePathForTerminal('C:\\foo'), 'C:\\foo'); + assert.equal(TerminalPanel.preparePathForTerminal('C:\\foo bar'), '"C:\\foo bar"'); + return; + } + assert.equal(TerminalPanel.preparePathForTerminal('/a/\\foo bar"\'? ;\'?? :'), '/a/\\\\foo\\ bar\\"\\\'\\?\\ \\;\\\'\\?\\?\\ \\ \\:'); + assert.equal(TerminalPanel.preparePathForTerminal('/\\\'"?:;!*(){}[]'), '/\\\\\\\'\\"\\?\\:\\;\\!\\*\\(\\)\\{\\}\\[\\]'); + }); +}); \ No newline at end of file