Skip to content

Commit

Permalink
Check the path for spaces before sending. Avoids filenames to be inte…
Browse files Browse the repository at this point in the history
…rpreted as file and arguments (microsoft#56966)

And added full escaping of space and escaped backslash on not Windows

Fixes microsoft#56109
  • Loading branch information
luiszun authored and alexr00 committed Sep 20, 2018
1 parent 10ee597 commit 5867dc7
Showing 1 changed file with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace
import { PICK_WORKSPACE_FOLDER_COMMAND_ID } from 'vs/workbench/browser/actions/workspaceCommands';
import { INotificationService } from 'vs/platform/notification/common/notification';
import { TERMINAL_COMMAND_ID } from 'vs/workbench/parts/terminal/common/terminalCommands';
import { isWindows } from 'vs/base/common/platform';
import { Command } from 'vs/editor/browser/editorExtensions';
import { timeout } from 'vs/base/common/async';
import { FindReplaceState } from 'vs/editor/contrib/find/findState';
Expand Down Expand Up @@ -654,7 +655,22 @@ export class RunActiveFileInTerminalAction extends Action {
this.notificationService.warn(nls.localize('workbench.action.terminal.runActiveFile.noFile', 'Only files on disk can be run in the terminal'));
return TPromise.as(void 0);
}
instance.sendText(uri.fsPath, true);
let uriPath: string = uri.fsPath;
const hasSpace = uriPath.indexOf(' ') !== -1;
if (hasSpace && isWindows) {
uriPath = '"' + uriPath + '"';
} else if (!isWindows) {
if (uriPath.indexOf('\\') !== 0) {
uriPath = uriPath.replace(/\\/g, '\\\\');
}
const hasDoubleQuote = uriPath.indexOf('"') !== -1;
if (!hasSpace && hasDoubleQuote) {
uriPath = '\'' + uriPath + '\'';
} else if (hasSpace) {
uriPath = uriPath.replace(/ /g, '\\ ');
}
}
instance.sendText(uriPath, true);
return this.terminalService.showPanel();
}
}
Expand Down

0 comments on commit 5867dc7

Please sign in to comment.