diff --git a/src/calibre/ebooks/epub/split.py b/src/calibre/ebooks/epub/split.py index 680a7e3e93..33c6360495 100644 --- a/src/calibre/ebooks/epub/split.py +++ b/src/calibre/ebooks/epub/split.py @@ -40,7 +40,7 @@ class Splitter(LoggingInterface): self.setup_cli_handler(opts.verbose) self.path = path self.always_remove = always_remove - self.base = os.path.splitext(path)[0] + '_split_%d.html' + self.base = (os.path.splitext(path)[0].replace('%', '%%') + '_split_%d.html') self.opts = opts self.orig_size = os.stat(content(path)).st_size self.log_info('\tSplitting %s (%d KB)', path, self.orig_size/1024.) @@ -341,7 +341,12 @@ def split(pathtoopf, opts): html_files = [] for item in opf.itermanifest(): if 'html' in item.get('media-type', '').lower(): - html_files.append(item.get('href').split('/')[-1]) + f = item.get('href').split('/')[-1] + f2 = f.replace('&', '%26') + if not os.path.exists(content(f)) and os.path.exists(content(f2)): + f = f2 + item.set('href', item.get('href').replace('&', '%26')) + html_files.append(f) changes = [] for f in html_files: if os.stat(content(f)).st_size > opts.profile.flow_size: diff --git a/src/calibre/ebooks/html.py b/src/calibre/ebooks/html.py index 2524987d08..147e4a8a79 100644 --- a/src/calibre/ebooks/html.py +++ b/src/calibre/ebooks/html.py @@ -238,6 +238,13 @@ def opf_traverse(opf_reader, verbose=0, encoding=None): path = os.path.abspath(item.path) if path not in flat: flat.append(path) + for i, path in enumerate(flat): + if not os.path.exists(path): + path = path.replace('&', '%26') + if os.path.exists(path): + flat[i] = path + for item in opf_reader.itermanifest(): + item.set('href', item.get('href').replace('&', '%26')) flat = [HTMLFile(path, 0, encoding, verbose) for path in flat] return [f for f in flat if not f.is_binary]