From 68edcec23211642f016ab2c3a8c397c19f015765 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 29 May 2014 09:33:10 +0530 Subject: [PATCH] Fix #1324162 [Authors gives error: unhandled exception / IndexError:string index out of range](https://bugs.launchpad.net/calibre/+bug/1324162) --- src/calibre/db/backend.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/calibre/db/backend.py b/src/calibre/db/backend.py index bcf02f9704..b40fcc2794 100644 --- a/src/calibre/db/backend.py +++ b/src/calibre/db/backend.py @@ -1111,8 +1111,11 @@ class DB(object): l = self.PATH_LIMIT - (len(book_id) // 2) - 2 author = ascii_filename(author)[:l].decode('ascii', 'replace') title = ascii_filename(title)[:l].decode('ascii', 'replace') - while author[-1] in (' ', '.'): - author = author[:-1] + try: + while author[-1] in (' ', '.'): + author = author[:-1] + except IndexError: + author = '' if not author: author = ascii_filename(_('Unknown')).decode( 'ascii', 'replace') @@ -1135,6 +1138,8 @@ class DB(object): name = title + ' - ' + author while name.endswith('.'): name = name[:-1] + if not name: + name = ascii_filename(_('Unknown')).decode('ascii', 'replace') return name # Database layer API {{{