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,15 @@ 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;
if ((uriPath.indexOf(' ') !== -1) || (uriPath.indexOf('"') !== -1)) {
if (isWindows) {
uriPath = '"' + uriPath + '"';
} else {
uriPath = '\'' + uriPath + '\'';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Escaping on macOS and Linux would probably be better done by escaping each space, this is more typical than quoting the whole path. This is what happens when you drag a file in that contains spaces: /Users/daimms/Desktop/Screen\ Shot\ 2018-09-14\ at\ 12.39.14\ PM.png

}
}
instance.sendText(uriPath, true);
return this.terminalService.showPanel();
}
}
Expand Down