From b3ec54636d22c59d2fa2736a1d183fa9988278d1 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 13 Oct 2016 09:13:01 +0530 Subject: [PATCH] Have abshref() return unparseable hrefs unchanged --- src/calibre/ebooks/oeb/base.py | 5 ++++- src/calibre/ebooks/oeb/polish/container.py | 7 ++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/calibre/ebooks/oeb/base.py b/src/calibre/ebooks/oeb/base.py index d6377dbf52..36c46a81c0 100644 --- a/src/calibre/ebooks/oeb/base.py +++ b/src/calibre/ebooks/oeb/base.py @@ -1108,7 +1108,10 @@ class Manifest(object): """Convert the URL provided in :param:`href` from a reference relative to this manifest item to a book-absolute reference. """ - purl = urlparse(href) + try: + purl = urlparse(href) + except ValueError: + return href scheme = purl.scheme if scheme and scheme != 'file': return href diff --git a/src/calibre/ebooks/oeb/polish/container.py b/src/calibre/ebooks/oeb/polish/container.py index b38a0babe2..198cfae728 100644 --- a/src/calibre/ebooks/oeb/polish/container.py +++ b/src/calibre/ebooks/oeb/polish/container.py @@ -97,7 +97,10 @@ def name_to_href(name, root, base=None, quote=urlquote): def href_to_name(href, root, base=None): base = root if base is None else os.path.dirname(name_to_abspath(base, root)) - purl = urlparse(href) + try: + purl = urlparse(href) + except ValueError: + return None if purl.scheme or not purl.path: return None href = urlunquote(purl.path) @@ -1458,5 +1461,3 @@ def test_roundtrip(): if __name__ == '__main__': test_roundtrip() - -