diff --git a/src/calibre/ebooks/conversion/plugins/html_input.py b/src/calibre/ebooks/conversion/plugins/html_input.py index eb26b5c6ed..5bc4f2577c 100644 --- a/src/calibre/ebooks/conversion/plugins/html_input.py +++ b/src/calibre/ebooks/conversion/plugins/html_input.py @@ -86,7 +86,7 @@ class HTMLInput(InputFormatPlugin): if hasattr(stream, 'name'): basedir = os.path.dirname(stream.name) fname = os.path.basename(stream.name) - self.root_dir_of_input = os.path.abspath(basedir) + os.sep + self.root_dir_of_input = os.path.normcase(os.path.abspath(basedir) + os.sep) if file_ext != 'opf': if opts.dont_package: @@ -262,7 +262,7 @@ class HTMLInput(InputFormatPlugin): if not link: return None, None link = os.path.abspath(os.path.realpath(link)) - if not link.startswith(self.root_dir_of_input): + if not os.path.normcase(link).startswith(self.root_dir_of_input): if not self.opts.allow_local_files_outside_root: self.log.warn('Not adding {} as it is outside the document root: {}'.format(link, self.root_dir_of_input)) return None, None diff --git a/src/calibre/ebooks/conversion/plugins/txt_input.py b/src/calibre/ebooks/conversion/plugins/txt_input.py index 6aa3c30ed4..550e066524 100644 --- a/src/calibre/ebooks/conversion/plugins/txt_input.py +++ b/src/calibre/ebooks/conversion/plugins/txt_input.py @@ -107,12 +107,13 @@ class TXTInput(InputFormatPlugin): from html5_parser import parse root = parse(html) changed = False + base_dir = os.path.normcase(os.path.abspath(base_dir)) + os.sep for img in root.xpath('//img[@src]'): src = img.get('src') prefix = src.split(':', 1)[0].lower() if src and prefix not in ('file', 'http', 'https', 'ftp') and not os.path.isabs(src): src = os.path.join(base_dir, src) - if os.path.isfile(src) and os.access(src, os.R_OK): + if os.path.normcase(src).startswith(base_dir) and os.path.isfile(src) and os.access(src, os.R_OK): with open(src, 'rb') as f: data = f.read() f = self.shift_file(os.path.basename(src), data)