Skip to content

Commit 9315887

Browse files
committed
Only quote arguments during cmdify if needed
1 parent 399c879 commit 9315887

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

pipenv/cmdparse.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,18 @@ def cmdify(self):
5555
5656
The result is then quoted into a pair of double quotes to be grouped.
5757
58+
An argument is intentionally not quoted if it does not contain
59+
whitespaces. This is done to be compatible with Windows built-in
60+
commands that don't work well with quotes, e.g. everything with `echo`,
61+
and DOS-style (forward slash) switches.
62+
5863
The intended use of this function is to pre-process an argument list
5964
before passing it into ``subprocess.Popen(..., shell=True)``.
6065
6166
See also: https://docs.python.org/3/library/subprocess.html#converting-argument-sequence
6267
"""
6368
return " ".join(
64-
'"{0}"'.format(re.sub(r'(\\*)"', r'\1\1\\"', arg)) for arg in self._parts
69+
arg if not next(re.finditer(r'\s', arg), None)
70+
else '"{0}"'.format(re.sub(r'(\\*)"', r'\1\1\\"', arg))
71+
for arg in self._parts
6572
)

tests/unit/test_cmdparse.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ def test_extend():
3030
@pytest.mark.run
3131
@pytest.mark.script
3232
def test_cmdify():
33-
script = Script('python', ['-c', "print('hello')"])
33+
script = Script('python', ['-c', "print('hello world')"])
3434
cmd = script.cmdify()
35-
assert cmd == '"python" "-c" "print(\'hello\')"', script
35+
assert cmd == 'python -c "print(\'hello world\')"', script
3636

3737

3838
@pytest.mark.run
@@ -44,6 +44,6 @@ def test_cmdify_complex():
4444
]))
4545
assert script.cmdify() == ' '.join([
4646
'"C:\\Program Files\\Python36\\python.exe"',
47-
'"-c"',
47+
'-c',
4848
""" "print(\'Double quote: \\\"\')" """.strip(),
4949
]), script

0 commit comments

Comments
 (0)