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.
This commit is contained in:
Kovid Goyal 2023-06-10 12:15:02 +05:30
parent 68f4b773f1
commit fdb68a1613
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 5 additions and 0 deletions

View File

@ -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

View File

@ -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: