Fix for bug #802159, not decoding of utf8 decoded values of custom display tags.

This commit is contained in:
Mattias Põldaru 2011-12-13 00:58:43 +02:00
parent 4949f88f28
commit e70ca4fa06
1 changed files with 16 additions and 6 deletions

View File

@ -149,11 +149,17 @@ class FormattingTags(object):
tags = [] tags = []
for tag in FormattingTags.html_expands: for tag in FormattingTags.html_expands:
if not tag[u'protected'] and not tag.get(u'temporary'): if not tag[u'protected'] and not tag.get(u'temporary'):
tags.append(tag) # Using dict ensures that copy is made and encoding of values
# Remove key 'temporary' from tags. It is not needed to be saved. # a little later does not affect tags in the original list
for tag in tags: tags.append(dict(tag))
if u'temporary' in tag: tag = tags[-1]
del tag[u'temporary'] # 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. # Formatting Tags were also known as display tags.
QtCore.QSettings().setValue(u'displayTags/html_tags', QtCore.QSettings().setValue(u'displayTags/html_tags',
QtCore.QVariant(cPickle.dumps(tags) if tags else u'')) 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', user_expands = QtCore.QSettings().value(u'displayTags/html_tags',
QtCore.QVariant(u'')).toString() QtCore.QVariant(u'')).toString()
# cPickle only accepts str not unicode strings # 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: if user_expands_string:
user_tags = cPickle.loads(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 # If we have some user ones added them as well
FormattingTags.add_html_tags(user_tags) FormattingTags.add_html_tags(user_tags)