Merge remote-tracking branch 'upstream/master'

This commit is contained in:
Serized 2017-07-15 16:28:05 +02:00
commit ae55d07a59
2 changed files with 13 additions and 2 deletions

View File

@ -22,7 +22,7 @@ from urlparse import urlparse
from cssutils import getUrls, replaceUrls from cssutils import getUrls, replaceUrls
from lxml import etree from lxml import etree
from calibre import CurrentDir from calibre import CurrentDir, walk
from calibre.constants import iswindows from calibre.constants import iswindows
from calibre.customize.ui import plugin_for_input_format, plugin_for_output_format from calibre.customize.ui import plugin_for_input_format, plugin_for_output_format
from calibre.ebooks import escape_xpath_attr 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. # assume all such paths are invalid/absolute paths.
return None return None
fullpath = os.path.join(base, *href.split('/')) 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): # {{{ class ContainerBase(object): # {{{
@ -1132,6 +1132,15 @@ class EpubContainer(Container):
os.remove(join(tdir, 'mimetype')) os.remove(join(tdir, 'mimetype'))
except EnvironmentError: except EnvironmentError:
pass 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') container_path = join(self.root, 'META-INF', 'container.xml')
if not exists(container_path): if not exists(container_path):

View File

@ -400,6 +400,8 @@ class OEBReader(object):
continue continue
href = item.abshref(urlnormalize(href[0])) if href and href[0] else '' href = item.abshref(urlnormalize(href[0])) if href and href[0] else ''
path, _ = urldefrag(href) 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: if href and path not in self.oeb.manifest.hrefs:
self.logger.warn('TOC reference %r not found' % href) self.logger.warn('TOC reference %r not found' % href)
gc = xpath(child, 'ncx:navPoint') gc = xpath(child, 'ncx:navPoint')