From e1a0e184c743de63f7737e340782200b2f0e777b Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 13 Dec 2016 14:40:50 +0530 Subject: [PATCH] EPUB Input: Fix incorrect handling of html files that are in a folder above the OPF file. Fixes #1649357 [Private bug](https://bugs.launchpad.net/calibre/+bug/1649357) --- src/calibre/ebooks/conversion/plugins/epub_input.py | 10 +++++++--- src/calibre/ebooks/oeb/reader.py | 1 + 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/calibre/ebooks/conversion/plugins/epub_input.py b/src/calibre/ebooks/conversion/plugins/epub_input.py index bcaab21a98..038625c1ea 100644 --- a/src/calibre/ebooks/conversion/plugins/epub_input.py +++ b/src/calibre/ebooks/conversion/plugins/epub_input.py @@ -3,7 +3,7 @@ __license__ = 'GPL 3' __copyright__ = '2009, Kovid Goyal ' __docformat__ = 'restructuredtext en' -import os, re +import os, re, posixpath from itertools import cycle from calibre.customize.conversion import InputFormatPlugin, OptionRecommendation @@ -265,10 +265,14 @@ class EPUBInput(InputFormatPlugin): if len(parts) > 1 and parts[0]: delta = '/'.join(parts[:-1])+'/' + + def normpath(x): + return posixpath.normpath(delta + elem.get('href')) + for elem in opf.itermanifest(): - elem.set('href', delta+elem.get('href')) + elem.set('href', normpath(elem.get('href'))) for elem in opf.iterguide(): - elem.set('href', delta+elem.get('href')) + elem.set('href', normpath(elem.get('href'))) f = self.rationalize_cover3 if opf.package_version >= 3.0 else self.rationalize_cover2 self.removed_cover = f(opf, log) diff --git a/src/calibre/ebooks/oeb/reader.py b/src/calibre/ebooks/oeb/reader.py index 58bb6b4156..5bc827ebde 100644 --- a/src/calibre/ebooks/oeb/reader.py +++ b/src/calibre/ebooks/oeb/reader.py @@ -713,5 +713,6 @@ def main(argv=sys.argv): print etree.tostring(doc, pretty_print=True) return 0 + if __name__ == '__main__': sys.exit(main())