aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2022-09-15 11:14:53 +0200
committerAnton Khirnov <anton@khirnov.net>2022-09-15 11:14:53 +0200
commit51461609a05743adae7018932a986e3f4455f55e (patch)
tree8cd563f6dfe2ec378e1b23b3a93e56ffa81d754d
parent548e62d41098579a82178bbcc74071998b573aca (diff)
Handle map characters outside of the alphabet.
Can happen when importing maps from elsewhere.
-rwxr-xr-xfshare.py8
1 files changed, 7 insertions, 1 deletions
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