- Notifications
You must be signed in to change notification settings - Fork18
Uh oh!
There was an error while loading.Please reload this page.
Conversation
This pull request has been linked toClubhouse Story #6190: Subtle bug(?) with coder sh handling of spaces. |
// $ coder sh go run ~/test.go 1 2 "3 4" '"abc def" \\abc' 5 6 "7 8 9" | ||
func shellEscape(arg string) string { | ||
r := strings.NewReplacer(`\`, `\\`, `"`, `\"`, `'`, `\'`, ` `, `\ `) | ||
return r.Replace(arg) |
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.
I think eventually we should be relying on shlex (or similar) to be parsing and escaping shell commands from strings into arg arrays, and avoid rolling our own for things like this.
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.
@tychoish Agree, I did a quick search bit didn't find any good ones. Happy to switch over now, or we can do it later, WDYT?
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.
https://github.com/google/shlex is functional.
I think this might also solve the %q question in the other PR
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.
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.
Hmm it looks like shlex is for parsing shell expressions, how do I use it to escape things?
The commands passed to "coder sh" are passed as a single argumentto "sh -c", so we need to shell-escape the command we pass.This change escapes spaces, backslash, and quotes.
Uh oh!
There was an error while loading.Please reload this page.
The commands passed to "coder sh" are passed as a single argument to "sh -c", so we need to shell-escape the command we pass. This change escapes spaces, backslash, and quotes.
I'm not 100% sure if this is a good idea, since it is a breaking change in case people have already been escaping their commands.
Note: this will need to be rebased once#226 is merged
Tested as follows:
For comparison, this is what
sh -c
andexec
would look like:And this was the previous behavior: