From 34ff4216d5b4700c50125b8e902c27183f225ab0 Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Mon, 14 Jun 2010 16:58:14 +0100 Subject: [PATCH] Ensure that strings are stripped before they are used --- src/calibre/gui2/dialogs/edit_authors_dialog.py | 6 +++--- src/calibre/library/database2.py | 7 +++++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/calibre/gui2/dialogs/edit_authors_dialog.py b/src/calibre/gui2/dialogs/edit_authors_dialog.py index 6e7eef3add..842fd7c943 100644 --- a/src/calibre/gui2/dialogs/edit_authors_dialog.py +++ b/src/calibre/gui2/dialogs/edit_authors_dialog.py @@ -59,8 +59,8 @@ class EditAuthorsDialog(QDialog, Ui_EditAuthorsDialog): self.result = [] for row in range(0,self.table.rowCount()): id = self.table.item(row, 0).data(Qt.UserRole).toInt()[0] - aut = unicode(self.table.item(row, 0).text()) - sort = unicode(self.table.item(row, 1).text()) + aut = unicode(self.table.item(row, 0).text()).strip() + sort = unicode(self.table.item(row, 1).text()).strip() orig_aut,orig_sort = self.authors[id] if orig_aut != aut or orig_sort != sort: self.result.append((id, orig_aut, aut, sort)) @@ -68,7 +68,7 @@ class EditAuthorsDialog(QDialog, Ui_EditAuthorsDialog): def cell_changed(self, row, col): if col == 0: item = self.table.item(row, 0) - aut = unicode(item.text()) + aut = unicode(item.text()).strip() c = self.table.item(row, 1) c.setText(author_to_author_sort(aut)) item = c diff --git a/src/calibre/library/database2.py b/src/calibre/library/database2.py index a8ac6ce5bf..2fb22a27f4 100644 --- a/src/calibre/library/database2.py +++ b/src/calibre/library/database2.py @@ -1045,6 +1045,7 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns): return result def rename_tag(self, old_id, new_name): + new_name = new_name.strip() new_id = self.conn.get( '''SELECT id from tags WHERE name=?''', (new_name,), all=False) @@ -1084,6 +1085,7 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns): return result def rename_series(self, old_id, new_name): + new_name = new_name.strip() new_id = self.conn.get( '''SELECT id from series WHERE name=?''', (new_name,), all=False) @@ -1128,6 +1130,7 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns): return result def rename_publisher(self, old_id, new_name): + new_name = new_name.strip() new_id = self.conn.get( '''SELECT id from publishers WHERE name=?''', (new_name,), all=False) @@ -1158,7 +1161,7 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns): def set_sort_field_for_author(self, old_id, new_sort): self.conn.execute('UPDATE authors SET sort=? WHERE id=?', \ - (new_sort, old_id)) + (new_sort.strip(), old_id)) self.conn.commit() # Now change all the author_sort fields in books by this author bks = self.conn.get('SELECT book from books_authors_link WHERE author=?', (old_id,)) @@ -1168,7 +1171,7 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns): def rename_author(self, old_id, new_name): # Make sure that any commas in new_name are changed to '|'! - new_name = new_name.replace(',', '|') + new_name = new_name.replace(',', '|').strip() # Get the list of books we must fix up, one way or the other # Save the list so we can use it twice