[New-bugs-announce] [issue27457] shlex.quote incorrectly quotes ampersants, pipes

klo uo report at bugs.python.org
Tue Jul 5 11:50:26 EDT 2016


New submission from klo uo:

Example code:

========================================
Python 3.4.3 (default, Oct 14 2015, 20:28:29)
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import shlex
>>> cmd = ["pwd", "&&", "ls"]
>>> ' '.join(shlex.quote(arg) for arg in cmd)
"pwd '&&' ls"
>>>
========================================

Double ampersants is quoted, and if this command string is passed to Popen or pasted in shell it would fail.


OTOH, Windows so-so compatible list2cmdline:

========================================
Python 3.5.1 (v3.5.1:37a07cee5969, Dec  6 2015, 01:54:25) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import subprocess
>>> cmd = ["cd", "&&", "dir"]
>>> subprocess.list2cmdline(cmd)
'cd && dir'
>>>
========================================

behaves correctly.

----------
messages: 269830
nosy: klo.uo
priority: normal
severity: normal
status: open
title: shlex.quote incorrectly quotes ampersants, pipes
type: behavior
versions: Python 3.4

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue27457>
_______________________________________


More information about the New-bugs-announce mailing list