diff --git a/src/calibre/__init__.py b/src/calibre/__init__.py index cbacf75271..5c6f43b09d 100644 --- a/src/calibre/__init__.py +++ b/src/calibre/__init__.py @@ -201,7 +201,7 @@ def sanitize_file_name(name): Also remove path separators. All illegal characters are replaced by underscores. ''' - return re.sub(r'\s', ' ', re.sub(r'["\'\|\~\:\?\\\/]|^-', '_', name.strip())) + return re.sub(r'\s', ' ', re.sub(r'[\xae"\'\|\~\:\?\\\/]|^-', '_', name.strip())) def detect_ncpus(): """Detects the number of effective CPUs in the system""" diff --git a/src/calibre/ebooks/lrf/lrfparser.py b/src/calibre/ebooks/lrf/lrfparser.py index 21d970ab29..f24b265a59 100644 --- a/src/calibre/ebooks/lrf/lrfparser.py +++ b/src/calibre/ebooks/lrf/lrfparser.py @@ -4,7 +4,7 @@ __copyright__ = '2008, Kovid Goyal ' import sys, array, os, re, codecs, logging -from calibre import setup_cli_handlers +from calibre import setup_cli_handlers, sanitize_file_name from calibre.utils.config import OptionParser from calibre.ebooks.lrf.meta import LRFMetaFile from calibre.ebooks.lrf.objects import get_object, PageTree, StyleObject, \ @@ -89,8 +89,9 @@ class LRFDocument(LRFMetaFile): bookinfo += u'%s\n\n\n'%(self.metadata.free_text,) th = self.doc_info.thumbnail if th: - bookinfo += u'\n'%(self.metadata.title+'_thumbnail.'+self.doc_info.thumbnail_extension,) - open(self.metadata.title+'_thumbnail.'+self.doc_info.thumbnail_extension, 'wb').write(th) + prefix = sanitize_file_name(self.metadata.title) + bookinfo += u'\n'%(prefix+'_thumbnail.'+self.doc_info.thumbnail_extension,) + open(prefix+'_thumbnail.'+self.doc_info.thumbnail_extension, 'wb').write(th) bookinfo += u'%s\n'%(self.doc_info.language,) bookinfo += u'%s\n'%(self.doc_info.creator,) bookinfo += u'%s\n'%(self.doc_info.producer,) diff --git a/src/calibre/library/database2.py b/src/calibre/library/database2.py index 363f2f509e..396c37a91b 100644 --- a/src/calibre/library/database2.py +++ b/src/calibre/library/database2.py @@ -35,7 +35,7 @@ def normpath(x): x = x.lower() return x -_filename_sanitize = re.compile(r'[\0\\|\?\*<":>\+\[\]/]') +_filename_sanitize = re.compile(r'[\xae\0\\|\?\*<":>\+\[\]/]') def sanitize_file_name(name, substitute='_'): ''' Sanitize the filename `name`. All invalid characters are replaced by `substitute`.