From 97ca819606b9c66a136d9128c723f2e53e698ba2 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 25 Aug 2016 21:22:25 +0530 Subject: [PATCH] DOCX Input: Fix images that have the # character in their filenames not being converted correctly. Fixes #1616482 [when converting to epub images do not appear](https://bugs.launchpad.net/calibre/+bug/1616482) --- src/calibre/ebooks/docx/images.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/calibre/ebooks/docx/images.py b/src/calibre/ebooks/docx/images.py index 471b50c4b1..10e64545c5 100644 --- a/src/calibre/ebooks/docx/images.py +++ b/src/calibre/ebooks/docx/images.py @@ -22,6 +22,9 @@ class LinkedImageNotFound(ValueError): ValueError.__init__(self, fname) self.fname = fname +def image_filename(x): + return ascii_filename(x).replace(' ', '_').replace('#', '_') + def emu_to_pt(x): return x / 12700 @@ -126,7 +129,7 @@ class Images(object): raw = rawsrc.read() else: raw = self.docx.read(fname) - base = base or ascii_filename(fname.rpartition('/')[-1]).replace(' ', '_') or 'image' + base = base or image_filename(fname.rpartition('/')[-1]) or 'image' ext = what(None, raw) or base.rpartition('.')[-1] or 'jpeg' if ext == 'emf': # For an example, see: https://bugs.launchpad.net/bugs/1224849 @@ -201,7 +204,7 @@ class Images(object): for pr in XPath('descendant::pic:cNvPr')(pic): name = pr.get('name', None) if name: - name = ascii_filename(name).replace(' ', '_') + name = image_filename(name) alt = pr.get('descr', None) for a in XPath('descendant::a:blip[@r:embed or @r:link]')(pic): rid = get(a, 'r:embed')