From fdb68a16133ecc966add15af975a13f5792c81a8 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 10 Jun 2023 12:15:02 +0530 Subject: [PATCH] CHM Input: resolve absolute links to resource files from the root of the CHM file. Fixes #2023431 [Private bug](https://bugs.launchpad.net/calibre/+bug/2023431) Previously they would have been ignored or caused an error on Windows. --- src/calibre/ebooks/conversion/plugins/chm_input.py | 1 + src/calibre/ebooks/conversion/plugins/html_input.py | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/src/calibre/ebooks/conversion/plugins/chm_input.py b/src/calibre/ebooks/conversion/plugins/chm_input.py index fbdfb48a52..d8a4428adc 100644 --- a/src/calibre/ebooks/conversion/plugins/chm_input.py +++ b/src/calibre/ebooks/conversion/plugins/chm_input.py @@ -104,6 +104,7 @@ class CHMInput(InputFormatPlugin): opts.breadth_first = True htmlinput = HTMLInput(None) htmlinput.set_root_dir_of_input(basedir) + htmlinput.root_dir_for_absolute_links = basedir oeb = htmlinput.create_oebbook(htmlpath, basedir, opts, log, mi) return oeb diff --git a/src/calibre/ebooks/conversion/plugins/html_input.py b/src/calibre/ebooks/conversion/plugins/html_input.py index c1d85b2d37..7957d0e230 100644 --- a/src/calibre/ebooks/conversion/plugins/html_input.py +++ b/src/calibre/ebooks/conversion/plugins/html_input.py @@ -37,6 +37,7 @@ class HTMLInput(InputFormatPlugin): description = _('Convert HTML and OPF files to an OEB') file_types = {'opf', 'html', 'htm', 'xhtml', 'xhtm', 'shtm', 'shtml'} commit_name = 'html_input' + root_dir_for_absolute_links = '' options = { OptionRecommendation(name='breadth_first', @@ -253,6 +254,9 @@ class HTMLInput(InputFormatPlugin): except: self.log.warn('Failed to decode link %r. Ignoring'%link_) return None, None + if self.root_dir_for_absolute_links and link_.startswith('/'): + link_ = link_.lstrip('/') + base = self.root_dir_for_absolute_links try: l = Link(link_, base if base else os.getcwd()) except: