From 8487bdb83e8e0ef4d310d73b30be254a8ba80925 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20H=C3=B6rist?= Date: Fri, 19 Oct 2018 15:59:04 +0200 Subject: [PATCH] Make bookmark parsing more resilient Fixes #9385 --- gajim/common/modules/bookmarks.py | 23 ++++++++++++++++------- gajim/common/modules/util.py | 10 +++------- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/gajim/common/modules/bookmarks.py b/gajim/common/modules/bookmarks.py index f2a6b0b28..b63aa808d 100644 --- a/gajim/common/modules/bookmarks.py +++ b/gajim/common/modules/bookmarks.py @@ -166,6 +166,7 @@ class Bookmarks: autojoin_val = conf.getAttr('autojoin') if not autojoin_val: # not there (it's optional) autojoin_val = False + minimize_val = conf.getTag('minimize', namespace=NS_GAJIM_BM) if not minimize_val: # not there, try old Gajim behaviour minimize_val = conf.getAttr('minimize') @@ -189,19 +190,27 @@ class Bookmarks: conf.getAttr('jid')) continue + bookmark = { + 'name': conf.getAttr('name'), + 'password': conf.getTagData('password'), + 'nick': conf.getTagData('nick'), + 'print_status': print_status + } + + try: + bookmark['autojoin'] = from_xs_boolean(autojoin_val) + bookmark['minimize'] = from_xs_boolean(minimize_val) + except ValueError as error: + log.warning(error) + continue + if check_merge: if jid in self.bookmarks: continue merged = True log.debug('Found Bookmark: %s', jid) - self.bookmarks[jid] = { - 'name': conf.getAttr('name'), - 'autojoin': from_xs_boolean(autojoin_val), - 'minimize': from_xs_boolean(minimize_val), - 'password': conf.getTagData('password'), - 'nick': conf.getTagData('nick'), - 'print_status': print_status} + self.bookmarks[jid] = bookmark return merged diff --git a/gajim/common/modules/util.py b/gajim/common/modules/util.py index 16ed56f68..810e6d38d 100644 --- a/gajim/common/modules/util.py +++ b/gajim/common/modules/util.py @@ -47,20 +47,16 @@ def is_muc_pm(message: nbxmpp.Node, def from_xs_boolean(value: Union[str, bool]) -> bool: - # Convert a xs:boolean ('true', 'false', '1', '0', '') - # to a python boolean (True, False) if isinstance(value, bool): return value - if value in ('1', 'true'): + if value in ('1', 'true', 'True'): return True - # '0', 'false' or empty - if value in ('0', 'false', ''): + if value in ('0', 'false', 'False', ''): return False - raise ValueError( - 'Cant convert %s to python boolean' % value) + raise ValueError('Cant convert %s to python boolean' % value) def to_xs_boolean(value: Union[bool, None]) -> str: