From 8ae0a180c15d992212329d87550eb48f9ece7190 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 15 Feb 2015 08:49:48 +0530 Subject: [PATCH] Conversion: Ignore incorrectly URL encoded links instead of erroring out on them. Fixes #1421996 [Private bug](https://bugs.launchpad.net/calibre/+bug/1421996) --- src/calibre/ebooks/oeb/transforms/structure.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/calibre/ebooks/oeb/transforms/structure.py b/src/calibre/ebooks/oeb/transforms/structure.py index ce939a4fc3..83711eff04 100644 --- a/src/calibre/ebooks/oeb/transforms/structure.py +++ b/src/calibre/ebooks/oeb/transforms/structure.py @@ -222,9 +222,13 @@ class DetectStructure(object): if (not self.opts.duplicate_links_in_toc and self.oeb.toc.has_text(text)): continue - num += 1 - self.oeb.toc.add(text, href, - play_order=self.oeb.toc.next_play_order()) + try: + self.oeb.toc.add(text, href, + play_order=self.oeb.toc.next_play_order()) + num += 1 + except ValueError: + self.oeb.log.exception('Failed to process link: %r' % href) + continue # Most likely an incorrectly URL encoded link if self.opts.max_toc_links > 0 and \ num >= self.opts.max_toc_links: self.log('Maximum TOC links reached, stopping.')