mirror of
https://github.com/kennethreitz/pipenv.git
synced 2026-06-05 22:50:18 +00:00
Apply script parsing fix from pypi/pipenv#1909
This commit is contained in:
+1
-3
@@ -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
@@ -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(),
|
||||
|
||||
Reference in New Issue
Block a user