Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
4341e54d
Commit
4341e54d
authored
Apr 24, 2010
by
Georg Brandl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#7507: quote "!" in pipes.quote(); it is a special character for some shells.
parent
f8bff488
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
12 additions
and
16 deletions
+12
-16
Lib/pipes.py
Lib/pipes.py
+6
-11
Lib/test/test_pipes.py
Lib/test/test_pipes.py
+4
-5
Misc/NEWS
Misc/NEWS
+2
-0
No files found.
Lib/pipes.py
View file @
4341e54d
...
...
@@ -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
(
"'"
,
"'
\
"
'
\
"
'"
)
+
"'"
Lib/test/test_pipes.py
View file @
4341e54d
...
...
@@ -64,9 +64,10 @@ class SimplePipeTests(unittest.TestCase):
self
.
assertEqual
(
open
(
TESTFN
).
read
(),
d
)
def
testQuoting
(
self
):
safeunquoted
=
string
.
ascii_letters
+
string
.
digits
+
'
!
@%_-+=:,./'
unsafe
=
'"`$
\
\
'
safeunquoted
=
string
.
ascii_letters
+
string
.
digits
+
'@%_-+=:,./'
unsafe
=
'"`$
\
\
!
'
self
.
assertEqual
(
pipes
.
quote
(
''
),
"''"
)
self
.
assertEqual
(
pipes
.
quote
(
safeunquoted
),
safeunquoted
)
self
.
assertEqual
(
pipes
.
quote
(
'test file name'
),
"'test file name'"
)
for
u
in
unsafe
:
...
...
@@ -74,9 +75,7 @@ class SimplePipeTests(unittest.TestCase):
"'test%sname'"
%
u
)
for
u
in
unsafe
:
self
.
assertEqual
(
pipes
.
quote
(
"test%s'name'"
%
u
),
'"test
\
\
%s
\
'
name
\
'
"'
%
u
)
self
.
assertEqual
(
pipes
.
quote
(
''
),
"''"
)
"'test%s'
\
"
'
\
"
'name'
\
"
'
\
"
''"
%
u
)
def
testRepr
(
self
):
t
=
pipes
.
Template
()
...
...
Misc/NEWS
View file @
4341e54d
...
...
@@ -25,6 +25,8 @@ Core and Builtins
Library
-------
- Issue #7507: Quote "!" in pipes.quote(); it is special to some shells.
- Issue #5238: Calling makefile() on an SSL object would prevent the
underlying socket from being closed until all objects get truely destroyed.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment