Apply script parsing fix from pypi/pipenv#1909

This commit is contained in:
Tzu-ping Chung
2018-04-05 16:31:32 +08:00
committed by Dan Ryan
parent 61418fda20
commit d1eeeced45
2 changed files with 12 additions and 6 deletions
+1 -3
View File
@@ -35,7 +35,7 @@ class Script(object):
def extend(self, extra_args):
self._parts.extend(extra_args)
def cmdify(self, extra_args=None):
def cmdify(self):
"""Encode into a cmd-executable string.
This re-implements CreateProcess's quoting logic to turn a list of
@@ -54,8 +54,6 @@ class Script(object):
See also: https://docs.python.org/3/library/subprocess.html#converting-argument-sequence
"""
if extra_args:
self.extend(extra_args)
return ' '.join(
'"{0}"'.format(re.sub(r'(\\*)"', r'\1\1\\"', arg))
for arg in self._parts
+11 -3
View File
@@ -12,12 +12,20 @@ def test_parse():
assert script.args == ['-c', "print('hello')"], script
@pytest.mark.run
def test_extend():
script = Script.parse(['python', '-c', "print('hello')"])
script.extend(['--verbose'])
assert script.command == 'python'
assert script.args == ['-c', "print('hello')", "--verbose"], script
@pytest.mark.run
@pytest.mark.script
def test_cmdify():
script = Script.parse(['python', '-c', "print('hello')"])
cmd = script.cmdify(['--verbose'])
assert cmd == '"python" "-c" "print(\'hello\')" "--verbose"', script
cmd = script.cmdify()
assert cmd == '"python" "-c" "print(\'hello\')"', script
@pytest.mark.run
@@ -27,7 +35,7 @@ def test_cmdify_complex():
'"C:\\Program Files\\Python36\\python.exe" -c',
""" "print(\'Double quote: \\\"\')" """.strip(),
]))
assert script.cmdify([]) == ' '.join([
assert script.cmdify() == ' '.join([
'"C:\\Program Files\\Python36\\python.exe"',
'"-c"',
""" "print(\'Double quote: \\\"\')" """.strip(),