From e70ca4fa063ddde262e12d37a1656ec58b3cad00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mattias=20P=C3=B5ldaru?= Date: Tue, 13 Dec 2011 00:58:43 +0200 Subject: [PATCH 1/2] Fix for bug #802159, not decoding of utf8 decoded values of custom display tags. --- openlp/core/lib/formattingtags.py | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/openlp/core/lib/formattingtags.py b/openlp/core/lib/formattingtags.py index ea5547f27..89f9fb837 100644 --- a/openlp/core/lib/formattingtags.py +++ b/openlp/core/lib/formattingtags.py @@ -149,11 +149,17 @@ class FormattingTags(object): tags = [] for tag in FormattingTags.html_expands: if not tag[u'protected'] and not tag.get(u'temporary'): - tags.append(tag) - # Remove key 'temporary' from tags. It is not needed to be saved. - for tag in tags: - if u'temporary' in tag: - del tag[u'temporary'] + # Using dict ensures that copy is made and encoding of values + # a little later does not affect tags in the original list + tags.append(dict(tag)) + tag = tags[-1] + # Remove key 'temporary' from tags. + # It is not needed to be saved. + if u'temporary' in tag: + del tag[u'temporary'] + for e in tag: + if isinstance(tag[e], unicode): + tag[e] = tag[e].encode('utf8') # Formatting Tags were also known as display tags. QtCore.QSettings().setValue(u'displayTags/html_tags', QtCore.QVariant(cPickle.dumps(tags) if tags else u'')) @@ -171,9 +177,13 @@ class FormattingTags(object): user_expands = QtCore.QSettings().value(u'displayTags/html_tags', QtCore.QVariant(u'')).toString() # cPickle only accepts str not unicode strings - user_expands_string = str(unicode(user_expands).encode(u'utf8')) + user_expands_string = str(user_expands) if user_expands_string: user_tags = cPickle.loads(user_expands_string) + for tag in user_tags: + for e in tag: + if isinstance(tag[e], str): + tag[e] = tag[e].decode('utf8') # If we have some user ones added them as well FormattingTags.add_html_tags(user_tags) From 9f5c0645aa9c9e60ff1c6faa28842c8becb4b889 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mattias=20P=C3=B5ldaru?= Date: Tue, 13 Dec 2011 12:58:33 +0200 Subject: [PATCH 2/2] No silly name abbreviations anymore. --- openlp/core/lib/formattingtags.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/openlp/core/lib/formattingtags.py b/openlp/core/lib/formattingtags.py index 89f9fb837..bc0055325 100644 --- a/openlp/core/lib/formattingtags.py +++ b/openlp/core/lib/formattingtags.py @@ -157,9 +157,9 @@ class FormattingTags(object): # It is not needed to be saved. if u'temporary' in tag: del tag[u'temporary'] - for e in tag: - if isinstance(tag[e], unicode): - tag[e] = tag[e].encode('utf8') + for element in tag: + if isinstance(tag[element], unicode): + tag[element] = tag[element].encode('utf8') # Formatting Tags were also known as display tags. QtCore.QSettings().setValue(u'displayTags/html_tags', QtCore.QVariant(cPickle.dumps(tags) if tags else u'')) @@ -181,9 +181,9 @@ class FormattingTags(object): if user_expands_string: user_tags = cPickle.loads(user_expands_string) for tag in user_tags: - for e in tag: - if isinstance(tag[e], str): - tag[e] = tag[e].decode('utf8') + for element in tag: + if isinstance(tag[element], str): + tag[element] = tag[element].decode('utf8') # If we have some user ones added them as well FormattingTags.add_html_tags(user_tags)