Fix #1324162 [Authors gives error: unhandled exception / IndexError:string index out of range](https://bugs.launchpad.net/calibre/+bug/1324162)

This commit is contained in:
Kovid Goyal 2014-05-29 09:33:10 +05:30
parent 06ba143405
commit 68edcec232

View File

@ -1111,8 +1111,11 @@ class DB(object):
l = self.PATH_LIMIT - (len(book_id) // 2) - 2 l = self.PATH_LIMIT - (len(book_id) // 2) - 2
author = ascii_filename(author)[:l].decode('ascii', 'replace') author = ascii_filename(author)[:l].decode('ascii', 'replace')
title = ascii_filename(title)[:l].decode('ascii', 'replace') title = ascii_filename(title)[:l].decode('ascii', 'replace')
while author[-1] in (' ', '.'): try:
author = author[:-1] while author[-1] in (' ', '.'):
author = author[:-1]
except IndexError:
author = ''
if not author: if not author:
author = ascii_filename(_('Unknown')).decode( author = ascii_filename(_('Unknown')).decode(
'ascii', 'replace') 'ascii', 'replace')
@ -1135,6 +1138,8 @@ class DB(object):
name = title + ' - ' + author name = title + ' - ' + author
while name.endswith('.'): while name.endswith('.'):
name = name[:-1] name = name[:-1]
if not name:
name = ascii_filename(_('Unknown')).decode('ascii', 'replace')
return name return name
# Database layer API {{{ # Database layer API {{{