-
Notifications
You must be signed in to change notification settings - Fork 10
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
Setting shell=False
requires the command to be an list of strings
#382
Comments
@drdavella just to be clear since you did not specify the codemod, it's |
This is a good refinement, so I'm bringing this test case that I thought about to see how we want to handle it. Say we want to run There are more complicated ways to handle shell features like a pipe, we could use Popen and subprocess.PIPE, but that deviates from the purpose of this codemod I feel like. So what do we want to do? Do we want to check if strings like "|" or other shell feature strings are present and not change it? |
@clavedeluna that's a really good question. There are definitely valid cases for using |
Would be a similar logic to #263
don't do anything
|
subprocess actually does not require a list of strings when run with Args are handled as a list regardless of the arg type. So to fully solve this issue two things are needed:
If the type can be determined to be a string or bytes, then Thanks guys have a great weekend! In 3.11 this is at line 1800 of subprocess.py if isinstance(args, (str, bytes)):
args = [args] # String or bytes arg are allowed when shell=True, string or bytes are then placed in list
elif isinstance(args, os.PathLike):
if shell:
raise TypeError('path-like args is not allowed when '
'shell is true')
args = [args]
else:
args = list(args)
if shell:
# On Android the default shell is at '/system/bin/sh'.
unix_shell = ('/system/bin/sh' if
hasattr(sys, 'getandroidapilevel') else '/bin/sh')
args = [unix_shell, "-c"] + args
if executable:
args[0] = executable
if executable is None:
executable = args[0] |
Right now our codemod does not account for the fact that in most cases for
shell=False
to work the command needs to be a list of strings rather than a single string.For example, the following is valid:
Whereas the following is not:
Instead, it needs to be the following:
We have a few options here but the most correct is probably to do the following:
The text was updated successfully, but these errors were encountered: