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.
This commit is contained in:
Eli Schwartz 2019-05-17 19:12:56 -04:00
parent ab7e134a40
commit 00ed9305cb
No known key found for this signature in database
GPG Key ID: CEB167EFB5722BD6

View File

@ -391,7 +391,7 @@ class Mobi8Reader(object):
fi = self.get_file_info(pos) fi = self.get_file_info(pos)
if fi.filename is None: if fi.filename is None:
raise ValueError('Index entry has invalid pos: %d'%pos) 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) href = '%s/%s'%(fi.type, fi.filename)
else: else:
try: try:
@ -403,7 +403,7 @@ class Mobi8Reader(object):
continue continue
entry['href'] = href entry['href'] = href
entry['idtag'] = idtag entry['idtag'] = idtag.decode(self.header.codec)
for e in remove: for e in remove:
index_entries.remove(e) index_entries.remove(e)