Fix bug #1098075: Cancelling character table dialog in song importer causes OpenLP to crash

bzr-revno: 2131
Fixes: https://launchpad.net/bugs/1098075
This commit is contained in:
Philip Ridout 2013-02-05 21:44:46 +02:00 committed by Raoul Snyman
commit 04b06ceac9
4 changed files with 14 additions and 3 deletions

View File

@ -581,6 +581,8 @@ def strip_rtf(text, default_encoding=None):
try:
encoding, default_encoding = get_encoding(font,
font_table, default_encoding, failed=failed)
if not encoding:
return None
out.append(chr(charcode).decode(encoding))
except UnicodeDecodeError:
failed = True

View File

@ -180,7 +180,10 @@ class EasyWorshipSongImport(SongImport):
self.addAuthor(author_name.strip())
if words:
# Format the lyrics
words, self.encoding = strip_rtf(words, self.encoding)
result = strip_rtf(words, self.encoding)
if result is None:
return
words, self.encoding = result
verse_type = VerseType.Tags[VerseType.Verse]
for verse in SLIDE_BREAK_REGEX.split(words):
verse = verse.strip()

View File

@ -109,7 +109,10 @@ class SongProImport(SongImport):
self.finish()
return
if u'rtf1' in text:
text, self.encoding = strip_rtf(text, self.encoding)
result = strip_rtf(text, self.encoding)
if result is None:
return
text, self.encoding = result
text = text.rstrip()
if not text:
return

View File

@ -150,7 +150,10 @@ class SundayPlusImport(SongImport):
verse_type = HOTKEY_TO_VERSE_TYPE[value]
if name == 'rtf':
value = self.unescape(value)
verse, self.encoding = strip_rtf(value, self.encoding)
result = strip_rtf(value, self.encoding)
if result is None:
return
verse, self.encoding = result
lines = verse.strip().split('\n')
# If any line inside any verse contains CCLI or
# only Public Domain, we treat this as special data: