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: try:
encoding, default_encoding = get_encoding(font, encoding, default_encoding = get_encoding(font,
font_table, default_encoding, failed=failed) font_table, default_encoding, failed=failed)
if not encoding:
return None
out.append(chr(charcode).decode(encoding)) out.append(chr(charcode).decode(encoding))
except UnicodeDecodeError: except UnicodeDecodeError:
failed = True failed = True

View File

@ -180,7 +180,10 @@ class EasyWorshipSongImport(SongImport):
self.addAuthor(author_name.strip()) self.addAuthor(author_name.strip())
if words: if words:
# Format the lyrics # 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] verse_type = VerseType.Tags[VerseType.Verse]
for verse in SLIDE_BREAK_REGEX.split(words): for verse in SLIDE_BREAK_REGEX.split(words):
verse = verse.strip() verse = verse.strip()

View File

@ -109,7 +109,10 @@ class SongProImport(SongImport):
self.finish() self.finish()
return return
if u'rtf1' in text: 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() text = text.rstrip()
if not text: if not text:
return return

View File

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