You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
A common problem/confusion in plugin code is remembering to (and remembering how to!) properly quote/escape command arguments when calling run_bash. This is because we're forcing the plugin to represent the entire command line as one single string.
For example, let's say I want to rename a remote file. I might be tempted to write this:
To get around this, some plugins have written their own function quote_for_bash. This function will take in a Python string representing the exact thing they want to pass as an argument, and will return a string that is quoted/escaped so that it is safe to pass as a single argument on a Bash command line:
Describe the solution you'd like
I'd suggest we do the same thing that Python's subprocess.run does. Namely, it allows for the user to provide a list of strings. Each string becomes its own separate argument:
As with subprocess.run, we could of course continue to support use of one single string for the whole command line, as well as this list approach.
Describe alternatives you've considered
The quote_for_bash idea the plugins are using looks like this:
def quote_for_bash(raw_string):
# Escape any single-quote characters in the raw string
string_to_quote = raw_string.replace("'", "'\"'\"'")
# Surround the string with single quotes
return "'{}'".format(string_to_quote)
This is easy enough to write. What's hard is remembering to use it, and remembering when you have to use it and when you don't.
The text was updated successfully, but these errors were encountered:
Is your feature request related to a problem? Please describe.
A common problem/confusion in plugin code is remembering to (and remembering how to!) properly quote/escape command arguments when calling
run_bash
. This is because we're forcing the plugin to represent the entire command line as one single string.For example, let's say I want to rename a remote file. I might be tempted to write this:
But that will fail if either filename has a space in it.
So, maybe this:
but that fails if the filename has interpolatable characters in it (such as dollar signs).
Similarly, this will fail if either filename has an apostrophe in it:
To get around this, some plugins have written their own function
quote_for_bash
. This function will take in a Python string representing the exact thing they want to pass as an argument, and will return a string that is quoted/escaped so that it is safe to pass as a single argument on a Bash command line:Describe the solution you'd like
I'd suggest we do the same thing that Python's
subprocess.run
does. Namely, it allows for the user to provide a list of strings. Each string becomes its own separate argument:As with
subprocess.run
, we could of course continue to support use of one single string for the whole command line, as well as this list approach.Describe alternatives you've considered
The
quote_for_bash
idea the plugins are using looks like this:This is easy enough to write. What's hard is remembering to use it, and remembering when you have to use it and when you don't.
The text was updated successfully, but these errors were encountered: