From 00ed9305cbe53d3b933bd65b5a80e8806f511f54 Mon Sep 17 00:00:00 2001 From: Eli Schwartz Date: Fri, 17 May 2019 19:12:56 -0400 Subject: [PATCH] py3: fix mobi ncx get_id_tag/get_id_tag_by_pos_fid are internal functions that always return bytes, but when using the former proxied through the latter, we did not always decode the result in the process of generating an OPF. As a result, books would end up with nav links pointing to urls resembling "foo.html#b'anchor'". Fix by moving down the decode attempt to cover both, right before writing it back into the index_entries. --- src/calibre/ebooks/mobi/reader/mobi8.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/calibre/ebooks/mobi/reader/mobi8.py b/src/calibre/ebooks/mobi/reader/mobi8.py index 6fb58c62e7..452bdb7d63 100644 --- a/src/calibre/ebooks/mobi/reader/mobi8.py +++ b/src/calibre/ebooks/mobi/reader/mobi8.py @@ -391,7 +391,7 @@ class Mobi8Reader(object): fi = self.get_file_info(pos) if fi.filename is None: raise ValueError('Index entry has invalid pos: %d'%pos) - idtag = self.get_id_tag(pos).decode(self.header.codec) + idtag = self.get_id_tag(pos) href = '%s/%s'%(fi.type, fi.filename) else: try: @@ -403,7 +403,7 @@ class Mobi8Reader(object): continue entry['href'] = href - entry['idtag'] = idtag + entry['idtag'] = idtag.decode(self.header.codec) for e in remove: index_entries.remove(e)