diff --git a/src/calibre/gui2/tweak_book/editor/text.py b/src/calibre/gui2/tweak_book/editor/text.py index d310906ea4..79e57c1804 100644 --- a/src/calibre/gui2/tweak_book/editor/text.py +++ b/src/calibre/gui2/tweak_book/editor/text.py @@ -81,8 +81,11 @@ class PlainTextEdit(QPlainTextEdit): if hasattr(ans, 'rstrip'): ans = ans.rstrip('\0') else: # QString - while ans[-1] == '\0': - ans.chop(1) + try: + while ans[-1] == '\0': + ans.chop(1) + except IndexError: + pass # ans is an empty string return ans @pyqtSlot()