From 8d36d399d7480ceb3f769a3a32287c40915573bb Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 15 Jul 2017 14:27:32 +0530 Subject: [PATCH 1/2] Fix #1704225 [Private bug](https://bugs.launchpad.net/calibre/+bug/1704225) --- src/calibre/ebooks/oeb/reader.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/calibre/ebooks/oeb/reader.py b/src/calibre/ebooks/oeb/reader.py index 789f82c94a..bf005087f2 100644 --- a/src/calibre/ebooks/oeb/reader.py +++ b/src/calibre/ebooks/oeb/reader.py @@ -400,6 +400,8 @@ class OEBReader(object): continue href = item.abshref(urlnormalize(href[0])) if href and href[0] else '' path, _ = urldefrag(href) + if path and path not in self.oeb.manifest.hrefs: + path = urlnormalize(path) if href and path not in self.oeb.manifest.hrefs: self.logger.warn('TOC reference %r not found' % href) gc = xpath(child, 'ncx:navPoint') From 91872292d1e0e2c11078451b69e831398f5c7e8f Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 15 Jul 2017 16:08:22 +0530 Subject: [PATCH 2/2] A couple more places where NFC normalization was needed in the container. See #1704225 (Private bug) --- src/calibre/ebooks/oeb/polish/container.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/calibre/ebooks/oeb/polish/container.py b/src/calibre/ebooks/oeb/polish/container.py index f6855c9e71..5161f7166f 100644 --- a/src/calibre/ebooks/oeb/polish/container.py +++ b/src/calibre/ebooks/oeb/polish/container.py @@ -22,7 +22,7 @@ from urlparse import urlparse from cssutils import getUrls, replaceUrls from lxml import etree -from calibre import CurrentDir +from calibre import CurrentDir, walk from calibre.constants import iswindows from calibre.customize.ui import plugin_for_input_format, plugin_for_output_format from calibre.ebooks import escape_xpath_attr @@ -122,7 +122,7 @@ def href_to_name(href, root, base=None): # assume all such paths are invalid/absolute paths. return None fullpath = os.path.join(base, *href.split('/')) - return abspath_to_name(fullpath, root) + return unicodedata.normalize('NFC', abspath_to_name(fullpath, root)) class ContainerBase(object): # {{{ @@ -1132,6 +1132,15 @@ class EpubContainer(Container): os.remove(join(tdir, 'mimetype')) except EnvironmentError: pass + # Ensure all filenames are in NFC normalized form + # has no effect on HFS+ filesystems as they always store filenames + # in NFD form + for filename in walk(self.root): + n = unicodedata.normalize('NFC', filename) + if n != filename: + s = filename + 'suff1x' + os.rename(filename, s) + os.rename(s, n) container_path = join(self.root, 'META-INF', 'container.xml') if not exists(container_path):