Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Lib/subprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,7 @@ def list2cmdline(seq):
if result:
result.append(' ')

needquote = (" " in arg) or ("\t" in arg) or not arg
needquote = not arg or not set(" \t&<>^|").isdisjoint(arg)
if needquote:
result.append('"')

Expand Down
9 changes: 9 additions & 0 deletions Lib/test/test_subprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -3560,6 +3560,15 @@ def test_invalid_args(self):
"import sys; sys.exit(47)"],
preexec_fn=lambda: 1)

def test_args_quoting(self):
with tempfile.NamedTemporaryFile(suffix=".bat", delete_on_close=False) as f:
f.write(b"echo %*\n")
f.close()
p = subprocess.run([f.file.name, "a b", "", "c<>d", "e"],
capture_output=True)
self.assertEqual(p.returncode, 0, p.stderr)
self.assertEndsWith(p.stdout.strip(), b'"a b" "" "c<>d" e')

@support.cpython_only
def test_issue31471(self):
# There shouldn't be an assertion failure in Popen() in case the env
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
In :mod:`subprocess` on Windows, in addition to space, tab, and empty string, quote arguments containing
``&<>^|``. Patch by John Keith Hohm.
Loading