From ff293d73ac0b22622bc50c7fae95f828b2492126 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 10 Dec 2011 09:36:08 +0530 Subject: [PATCH] HTML Input: Ignore unparseable URLs instead of crashing on them. Fixes #902372 (HTML convert crashes with " Invalid IPv6 URL" error) --- src/calibre/ebooks/html/input.py | 6 +++++- src/calibre/ebooks/mobi/writer2/serializer.py | 6 +++++- src/calibre/ebooks/oeb/transforms/split.py | 6 +++++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/calibre/ebooks/html/input.py b/src/calibre/ebooks/html/input.py index e958b9dd27..ccbc987533 100644 --- a/src/calibre/ebooks/html/input.py +++ b/src/calibre/ebooks/html/input.py @@ -148,7 +148,11 @@ class HTMLFile(object): url = match.group(i) if url: break - link = self.resolve(url) + try: + link = self.resolve(url) + except ValueError: + # Unparseable URL, ignore + continue if link not in self.links: self.links.append(link) diff --git a/src/calibre/ebooks/mobi/writer2/serializer.py b/src/calibre/ebooks/mobi/writer2/serializer.py index 041a9922cb..5bf6b10d23 100644 --- a/src/calibre/ebooks/mobi/writer2/serializer.py +++ b/src/calibre/ebooks/mobi/writer2/serializer.py @@ -178,7 +178,11 @@ class Serializer(object): at the end. ''' hrefs = self.oeb.manifest.hrefs - path, frag = urldefrag(urlnormalize(href)) + try: + path, frag = urldefrag(urlnormalize(href)) + except ValueError: + # Unparseable URL + return False if path and base: path = base.abshref(path) if path and path not in hrefs: diff --git a/src/calibre/ebooks/oeb/transforms/split.py b/src/calibre/ebooks/oeb/transforms/split.py index 24af1aa4f7..96e4b08079 100644 --- a/src/calibre/ebooks/oeb/transforms/split.py +++ b/src/calibre/ebooks/oeb/transforms/split.py @@ -154,7 +154,11 @@ class Split(object): def rewrite_links(self, url): href, frag = urldefrag(url) - href = self.current_item.abshref(href) + try: + href = self.current_item.abshref(href) + except ValueError: + # Unparseable URL + return url if href in self.map: anchor_map = self.map[href] nhref = anchor_map[frag if frag else None]