mirror of https://github.com/pypa/pip
Change format_command() to use shlex.quote().
This commit is contained in:
parent
1d0645e86f
commit
0f6776388c
|
@ -0,0 +1,2 @@
|
|||
Command arguments in ``subprocess`` log messages are now quoted using
|
||||
``shlex.quote()``.
|
|
@ -23,7 +23,7 @@ from pip._vendor import pkg_resources
|
|||
# why we ignore the type on this import.
|
||||
from pip._vendor.retrying import retry # type: ignore
|
||||
from pip._vendor.six import PY2
|
||||
from pip._vendor.six.moves import input
|
||||
from pip._vendor.six.moves import input, shlex_quote
|
||||
from pip._vendor.six.moves.urllib import parse as urllib_parse
|
||||
from pip._vendor.six.moves.urllib.parse import unquote as urllib_unquote
|
||||
|
||||
|
@ -655,14 +655,7 @@ def format_command_args(args):
|
|||
"""
|
||||
Format command arguments for display.
|
||||
"""
|
||||
parts = []
|
||||
for arg in args:
|
||||
if ' ' in arg or '\n' in arg or '"' in arg or "'" in arg:
|
||||
arg = '"%s"' % arg.replace('"', '\\"')
|
||||
parts.append(arg)
|
||||
command = ' '.join(parts)
|
||||
|
||||
return command
|
||||
return ' '.join(shlex_quote(arg) for arg in args)
|
||||
|
||||
|
||||
def call_subprocess(
|
||||
|
|
|
@ -728,7 +728,7 @@ class TestGetProg(object):
|
|||
@pytest.mark.parametrize('args, expected', [
|
||||
(['pip', 'list'], 'pip list'),
|
||||
(['foo', 'space space', 'new\nline', 'double"quote', "single'quote"],
|
||||
'foo "space space" "new\nline" "double\\"quote" "single\'quote"'),
|
||||
"""foo 'space space' 'new\nline' 'double"quote' 'single'"'"'quote'"""),
|
||||
])
|
||||
def test_format_command_args(args, expected):
|
||||
actual = format_command_args(args)
|
||||
|
|
Loading…
Reference in New Issue