Skip to content

Commit 7453929

Browse files
committed
Fix: Keep unicode/str type in shell_escape()
1 parent 2641906 commit 7453929

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

debian/changelog

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
pyrobase (0.5.2) precise; urgency=low
2+
3+
* Fix: Keep unicode/str type in shell_escape()
4+
5+
-- pyroscope <[email protected]> Mon, 01 Jan 2018 14:03:46 +0100
6+
17
pyrobase (0.5.1) precise; urgency=low
28

39
* Removed support for Python 2.6

src/pyrobase/osutil.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,8 @@
2424

2525
def shell_escape(text, _safe=re.compile(r"^[-._,+a-zA-Z0-9]+$")):
2626
"""Escape given string according to shell rules."""
27-
return text if _safe.match(text) else "'%s'" % text.replace("'", r"'\''")
27+
if not text or _safe.match(text):
28+
return text
29+
30+
squote = type(text)("'")
31+
return squote + text.replace(squote, type(text)(r"'\''")) + squote

src/tests/test_osutil.py

+3
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ def test_shell_escape(self):
3333
("!bang", "'!bang'"),
3434
("d\"q", "'d\"q'"),
3535
("s'q", r"'s'\''q'"),
36+
(b"abc", b"abc"),
37+
(b"!bang", b"'!bang'"),
38+
(b"\xA0", b"'\xA0'"),
3639
]
3740
for val, expected in cases:
3841
result = osutil.shell_escape(val)

0 commit comments

Comments
 (0)