From 51461609a05743adae7018932a986e3f4455f55e Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Thu, 15 Sep 2022 11:14:53 +0200 Subject: Handle map characters outside of the alphabet. Can happen when importing maps from elsewhere. --- fshare.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/fshare.py b/fshare.py index 6528602..228f5e6 100755 --- a/fshare.py +++ b/fshare.py @@ -179,7 +179,13 @@ class URLMap: data = [l.strip().split() for l in self._file.readlines()] self._short_to_full = dict(data) self._full_to_short = dict(((b, a) for (a, b) in data)) - self._next_id = self._enc.decode_url(data[-1][0]) if len(data) else 0 + + try: + self._next_id = self._enc.decode_url(data[-1][0]) + except (IndexError, ValueError): + # data is empty or the mapping uses characters not in alphabet + self._next_id = 0 + except: self.close() raise -- cgit v1.2.3