diff options
author | hut <hut@lavabit.com> | 2011-12-03 00:27:10 +0100 |
---|---|---|
committer | hut <hut@lavabit.com> | 2011-12-17 22:17:12 +0100 |
commit | d99291d8395042ade1337d025a69eaccd191bb54 (patch) | |
tree | 3bf8201c99bac1d997da7d705e683120696e3da7 | |
parent | 7d820eebd049b8bf67a37ddd4046099e1569882c (diff) | |
download | ranger-d99291d8395042ade1337d025a69eaccd191bb54.tar.gz |
fsobject.fsobject: Properly escape control characters
-rw-r--r-- | ranger/fsobject/fsobject.py | 11 | ||||
-rw-r--r-- | ranger/gui/widgets/browsercolumn.py | 2 | ||||
-rw-r--r-- | ranger/gui/widgets/titlebar.py | 4 |
3 files changed, 14 insertions, 3 deletions
diff --git a/ranger/fsobject/fsobject.py b/ranger/fsobject/fsobject.py index 51e49808..1d1f202d 100644 --- a/ranger/fsobject/fsobject.py +++ b/ranger/fsobject/fsobject.py @@ -26,6 +26,12 @@ from ranger.ext.spawn import spawn from ranger.ext.lazy_property import lazy_property from ranger.ext.human_readable import human_readable +if hasattr(str, 'maketrans'): + maketrans = str.maketrans +else: + from string import maketrans +unsafe_chars = '\n' + ''.join(map(chr, range(32))) + ''.join(map(chr, range(128, 256))) +safe_string_table = maketrans(unsafe_chars, '?' * len(unsafe_chars)) _extract_number_re = re.compile(r'([^0-9]?)(\d*)') class FileSystemObject(FileManagerAware): @@ -106,6 +112,11 @@ class FileSystemObject(FileManagerAware): return [c if i % 3 == 1 else (int(c) if c else 0) for i, c in \ enumerate(_extract_number_re.split(self.basename_lower))] + @lazy_property + def safe_basename(self): + return self.basename.translate(safe_string_table) + + for attr in ('video', 'audio', 'image', 'media', 'document', 'container'): exec("%s = lazy_property(" "lambda self: self.set_mimetype() or self.%s)" % (attr, attr)) diff --git a/ranger/gui/widgets/browsercolumn.py b/ranger/gui/widgets/browsercolumn.py index b6b745aa..91633d4e 100644 --- a/ranger/gui/widgets/browsercolumn.py +++ b/ranger/gui/widgets/browsercolumn.py @@ -220,7 +220,7 @@ class BrowserColumn(Pager): bad_info_color = None this_color = base_color + list(drawn.mimetype_tuple) - text = drawn.basename + text = drawn.safe_basename tagged = self.fm.tags and drawn.realpath in self.fm.tags if tagged: diff --git a/ranger/gui/widgets/titlebar.py b/ranger/gui/widgets/titlebar.py index 3ca3f80d..ddb27f2c 100644 --- a/ranger/gui/widgets/titlebar.py +++ b/ranger/gui/widgets/titlebar.py @@ -124,11 +124,11 @@ class TitleBar(Widget): else: clr = 'directory' - bar.add(path.basename, clr, directory=path) + bar.add(path.safe_basename, clr, directory=path) bar.add('/', clr, fixed=True, directory=path) if self.env.cf is not None: - bar.add(self.env.cf.basename, 'file') + bar.add(self.env.cf.safe_basename, 'file') def _get_right_part(self, bar): # TODO: fix that pressed keys are cut off when chaining CTRL keys |