From 67176abadec9fa42b647f0432094257aa4bd5eb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C2=96bassantabdelaziz?= Date: Tue, 1 Aug 2023 16:20:10 +0300 Subject: [PATCH 1/4] add normalization to the files/chapters name --- ebooklib/epub.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ebooklib/epub.py b/ebooklib/epub.py index 34167cc..58306e5 100644 --- a/ebooklib/epub.py +++ b/ebooklib/epub.py @@ -22,6 +22,8 @@ import posixpath as zip_path import os.path from collections import OrderedDict +import unicodedata + try: from urllib.parse import unquote @@ -1415,6 +1417,7 @@ def load(self): def read_file(self, name): # Raises KeyError + unicodedata.normalize('NFC', name) name = zip_path.normpath(name) return self.zf.read(name) From fe844846dffc86f530f7baa405eca592c8f94159 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C2=96bassantabdelaziz?= Date: Tue, 1 Aug 2023 16:55:33 +0300 Subject: [PATCH 2/4] add normalization to the files/chapters name --- ebooklib/epub.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ebooklib/epub.py b/ebooklib/epub.py index 58306e5..eb19e6c 100644 --- a/ebooklib/epub.py +++ b/ebooklib/epub.py @@ -1417,8 +1417,8 @@ def load(self): def read_file(self, name): # Raises KeyError - unicodedata.normalize('NFC', name) name = zip_path.normpath(name) + normalized_name = unicodedata.normalize('NFC', name) return self.zf.read(name) def _load_container(self): From ab5a16caa272c729e1b85808cca87081953b3381 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C2=96bassantabdelaziz?= Date: Tue, 1 Aug 2023 16:56:52 +0300 Subject: [PATCH 3/4] use the normalized name --- ebooklib/epub.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ebooklib/epub.py b/ebooklib/epub.py index eb19e6c..ad9911f 100644 --- a/ebooklib/epub.py +++ b/ebooklib/epub.py @@ -1418,8 +1418,7 @@ def load(self): def read_file(self, name): # Raises KeyError name = zip_path.normpath(name) - normalized_name = unicodedata.normalize('NFC', name) - return self.zf.read(name) + return self.zf.read(unicodedata.normalize('NFC', name)) def _load_container(self): meta_inf = self.read_file('META-INF/container.xml') From 4cdc1ecf047aae5c65c2fda1e10399977f65bbab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C2=96bassantabdelaziz?= Date: Thu, 10 Aug 2023 04:00:59 +0300 Subject: [PATCH 4/4] use urllib.parse.unquote --- ebooklib/epub.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ebooklib/epub.py b/ebooklib/epub.py index ad9911f..4229a9e 100644 --- a/ebooklib/epub.py +++ b/ebooklib/epub.py @@ -23,7 +23,7 @@ import os.path from collections import OrderedDict import unicodedata - +import urllib try: from urllib.parse import unquote @@ -1418,7 +1418,9 @@ def load(self): def read_file(self, name): # Raises KeyError name = zip_path.normpath(name) - return self.zf.read(unicodedata.normalize('NFC', name)) + parsed_name = urllib.parse.unquote(name) + normalized_name = unicodedata.normalize('NFC', parsed_name) + return self.zf.read(normalized_name) def _load_container(self): meta_inf = self.read_file('META-INF/container.xml')