Philipp Hörist pushed to branch master at gajim / gajim

Commits:
8487bdb8 by Philipp Hörist at 2018-10-19T13:59:04Z
Make bookmark parsing more resilient

Fixes #9385

- - - - -


2 changed files:

- gajim/common/modules/bookmarks.py
- gajim/common/modules/util.py


Changes:

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


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



View it on GitLab: 
https://dev.gajim.org/gajim/gajim/commit/8487bdb83e8e0ef4d310d73b30be254a8ba80925

-- 
View it on GitLab: 
https://dev.gajim.org/gajim/gajim/commit/8487bdb83e8e0ef4d310d73b30be254a8ba80925
You're receiving this email because of your account on dev.gajim.org.
_______________________________________________
Commits mailing list
Commits@gajim.org
https://lists.gajim.org/cgi-bin/listinfo/commits

Reply via email to