Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check the path for spaces before sending. Avoids filenames to be inte… #56966

Merged
merged 6 commits into from Sep 20, 2018
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';

Expand Down Expand Up @@ -653,7 +654,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