diff options
-rw-r--r-- | ranger/container/bookmarks.py | 11 | ||||
-rw-r--r-- | tests/ranger/container/test_bookmarks.py | 9 |
2 files changed, 16 insertions, 4 deletions
diff --git a/ranger/container/bookmarks.py b/ranger/container/bookmarks.py index cbfc541a..7b5e56b7 100644 --- a/ranger/container/bookmarks.py +++ b/ranger/container/bookmarks.py @@ -88,7 +88,11 @@ class Bookmarks(FileManagerAware): if key == '`': key = "'" if key in self.dct: - return self.dct[key] + value = self.dct[key] + if self._validate(value): + return value + else: + raise KeyError("Cannot open bookmark: `%s'!" % key) else: raise KeyError("Nonexistant Bookmark: `%s'!" % key) @@ -229,7 +233,7 @@ class Bookmarks(FileManagerAware): for line in fobj: if self.load_pattern.match(line): key, value = line[0], line[2:-1] - if key in ALLOWED_KEYS and not os.path.isfile(value): + if key in ALLOWED_KEYS: dct[key] = self.bookmarktype(value) fobj.close() return dct @@ -253,3 +257,6 @@ class Bookmarks(FileManagerAware): def _update_mtime(self): self.last_mtime = self._get_mtime() + + def _validate(self, value): # pylint: disable=no-self-use + return os.path.isdir(str(value)) diff --git a/tests/ranger/container/test_bookmarks.py b/tests/ranger/container/test_bookmarks.py index 64192c06..84ac42c2 100644 --- a/tests/ranger/container/test_bookmarks.py +++ b/tests/ranger/container/test_bookmarks.py @@ -8,11 +8,16 @@ import pytest from ranger.container.bookmarks import Bookmarks +class NotValidatedBookmarks(Bookmarks): + def _validate(self, value): + return True + + def testbookmarks(tmpdir): # Bookmarks point to directory location and allow fast access to # 'favorite' directories. They are persisted to a bookmark file, plain text. bookmarkfile = tmpdir.join("bookmarkfile") - bmstore = Bookmarks(str(bookmarkfile)) + bmstore = NotValidatedBookmarks(str(bookmarkfile)) # loading an empty bookmark file doesnot crash bmstore.load() @@ -33,7 +38,7 @@ def testbookmarks(tmpdir): # We can persist bookmarks to disk and restore them from disk bmstore.save() - secondstore = Bookmarks(str(bookmarkfile)) + secondstore = NotValidatedBookmarks(str(bookmarkfile)) secondstore.load() assert "'" in secondstore assert secondstore["'"] == "the milk" |