summary refs log tree commit diff stats
path: root/ranger
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2012-01-11 11:03:27 +0100
committerhut <hut@lavabit.com>2012-01-11 16:57:46 +0100
commit999a9268aa3d8104d864131d7ad4ee6d6b2a643b (patch)
tree3dc1aebc8d06fcf55c1c9f37f66094a175b07a06 /ranger
parent8c917a95c27e5293f762b018edc0751e95cf9726 (diff)
downloadranger-999a9268aa3d8104d864131d7ad4ee6d6b2a643b.tar.gz
ext.shell_escape: Fixed escaping of tabs and unprintables
Diffstat (limited to 'ranger')
-rw-r--r--ranger/ext/shell_escape.py7
1 files changed, 5 insertions, 2 deletions
diff --git a/ranger/ext/shell_escape.py b/ranger/ext/shell_escape.py
index 28a502bf..b68afc33 100644
--- a/ranger/ext/shell_escape.py
+++ b/ranger/ext/shell_escape.py
@@ -18,17 +18,20 @@ Functions to escape metacharacters of arguments for shell commands.
 """
 
 META_CHARS = (' ', "'", '"', '`', '&', '|', ';',
-		'$', '!', '(', ')', '[', ']', '<', '>')
+		'$', '!', '(', ')', '[', ']', '<', '>', '\t')
+UNESCAPABLE = set(map(chr, list(range(9)) + list(range(10, 32)) \
+		+ list(range(127, 256))))
 META_DICT = dict([(mc, '\\' + mc) for mc in META_CHARS])
 
 def shell_quote(string):
 	"""Escapes by quoting"""
 	return "'" + str(string).replace("'", "'\\''") + "'"
 
-
 def shell_escape(arg):
 	"""Escapes by adding backslashes"""
 	arg = str(arg)
+	if UNESCAPABLE & set(arg):
+		return shell_quote(arg)
 	arg = arg.replace('\\', '\\\\') # make sure this comes at the start
 	for k, v in META_DICT.items():
 		arg = arg.replace(k, v)
#n154'>154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214