mirror of
https://github.com/python/cpython.git
synced 2025-12-04 00:30:19 +00:00
#7507: quote "!" in pipes.quote(); it is a special character for some shells.
This commit is contained in:
parent
f8bff488bd
commit
4341e54de8
3 changed files with 12 additions and 16 deletions
17
Lib/pipes.py
17
Lib/pipes.py
|
|
@ -263,11 +263,11 @@ def makepipeline(infile, steps, outfile):
|
|||
|
||||
# Reliably quote a string as a single argument for /bin/sh
|
||||
|
||||
_safechars = string.ascii_letters + string.digits + '!@%_-+=:,./' # Safe unquoted
|
||||
_funnychars = '"`$\\' # Unsafe inside "double quotes"
|
||||
# Safe unquoted
|
||||
_safechars = frozenset(string.ascii_letters + string.digits + '@%_-+=:,./')
|
||||
|
||||
def quote(file):
|
||||
''' return a shell-escaped version of the file string '''
|
||||
"""Return a shell-escaped version of the file string."""
|
||||
for c in file:
|
||||
if c not in _safechars:
|
||||
break
|
||||
|
|
@ -275,11 +275,6 @@ def quote(file):
|
|||
if not file:
|
||||
return "''"
|
||||
return file
|
||||
if '\'' not in file:
|
||||
return '\'' + file + '\''
|
||||
res = ''
|
||||
for c in file:
|
||||
if c in _funnychars:
|
||||
c = '\\' + c
|
||||
res = res + c
|
||||
return '"' + res + '"'
|
||||
# use single quotes, and put single quotes into double quotes
|
||||
# the string $'b is then quoted as '$'"'"'b'
|
||||
return "'" + file.replace("'", "'\"'\"'") + "'"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue