diff options
author | hut <hut@lavabit.com> | 2012-03-05 11:56:05 +0100 |
---|---|---|
committer | hut <hut@lavabit.com> | 2012-03-05 11:56:05 +0100 |
commit | e1155824b39d584beb8c178ceca8999eb7783daf (patch) | |
tree | 22dae0662d03ce8562159d9196fd8c854d6af009 /ranger/ext/shell_escape.py | |
parent | 2bcfbe93584f3e9bdd4f80ff4cce43e39a545914 (diff) | |
parent | 23b7f16961a7b679dec16f6ee91401a6b8f6ca82 (diff) | |
download | ranger-e1155824b39d584beb8c178ceca8999eb7783daf.tar.gz |
Merge branch 'master' into stable
Diffstat (limited to 'ranger/ext/shell_escape.py')
-rw-r--r-- | ranger/ext/shell_escape.py | 7 |
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) |