-
Notifications
You must be signed in to change notification settings - Fork 30k
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
Conversation
…rpreted as file and arguments
@@ -638,7 +638,11 @@ 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) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A space on Mac/Linux should be escaped with a \\
in front of it.
We should also consider and handle paths that contain the "
character.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The " character is not allowed in Windows.
I thought it was the same in Unixes, but you're right! Some shells will not allow it, but at least the major filesystems allow it (ext3, ext4). I'll get educated on Mac, and I'll change the PR.
Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mac allows it, just testing Linux and treating mac the same should be enough 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like on Linux space can also be dealt with by surrounding with single quotes.
I tested using WSL and this path: ~tes"t/test script.bash |
I thought of doing the single quote thing, but I found out that some filesystems (ext4 being a very widely used one) allow all characters except '' and null. Though I doubt escaping non-printable characters is a practical solution. I think that for all practical purposes, the single quote suffices. Just wanted to drop this piece of data :) |
if (isWindows) { | ||
uriPath = '"' + uriPath + '"'; | ||
} else { | ||
uriPath = '\'' + uriPath + '\''; |
There was a problem hiding this comment.
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
if (!hasSpace && hasDoubleQuote) { | ||
uriPath = '\'' + uriPath + '\''; | ||
} else if (hasSpace) { | ||
uriPath = uriPath.replace(' ', '\\ '); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.replace
only replaces the first instance.
I think we also need to handle \\
-> \\\\
@luiszun could you please sign the CLA mentioned in #56966 (comment) so we can get this merged? |
Looks good to me, just waiting on the CLA |
Supposedly I didn't have to sign the CLA if I linked my Microsoft corp account to this profile. Anyway, just signed it. Sorry for the delay |
Check the path for spaces before sending. Avoids filenames to be interpreted as file and arguments
Closes #56109