From 085e813cbcd62a5ef80183fd15e84666520509ea Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 21 Aug 2018 22:43:30 +0530 Subject: [PATCH] HTML Input: Collapse multiple spaces in filenames when sanitizing them. Fixes #1788187 [When creating epub references with spaces in content.opf should be transformed in %20](https://bugs.launchpad.net/calibre/+bug/1788187) --- src/calibre/ebooks/conversion/plugins/html_input.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/calibre/ebooks/conversion/plugins/html_input.py b/src/calibre/ebooks/conversion/plugins/html_input.py index fa9329fc40..5717e79b24 100644 --- a/src/calibre/ebooks/conversion/plugins/html_input.py +++ b/src/calibre/ebooks/conversion/plugins/html_input.py @@ -20,7 +20,9 @@ from calibre.utils.imghdr import what def sanitize_file_name(x): - return re.sub(r'[?&=;#]', '_', ascii_filename(x)) + ans = re.sub(r'\s+', ' ', re.sub(r'[?&=;#]', '_', ascii_filename(x))).strip().rstrip('.') + ans, ext = ans.rpartition('.')[::2] + return ans.strip() + '.' + ext.strip() class HTMLInput(InputFormatPlugin):