Make bookmark parsing more resilient

Fixes #9385
This commit is contained in:
Philipp Hörist 2018-10-19 15:59:04 +02:00
parent 479bfa56cb
commit f51c6f6b18
2 changed files with 19 additions and 14 deletions

View File

@ -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

View File

@ -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: