From ca0a977b09a8c1e4a55a7dd9785a77375203f3aa Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 4 Feb 2022 16:41:08 +0530 Subject: [PATCH] Better handling of empty prefix list --- src/calibre/ebooks/metadata/__init__.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/calibre/ebooks/metadata/__init__.py b/src/calibre/ebooks/metadata/__init__.py index 1a62f8eaaa..9ee0054b63 100644 --- a/src/calibre/ebooks/metadata/__init__.py +++ b/src/calibre/ebooks/metadata/__init__.py @@ -163,12 +163,15 @@ def get_title_sort_pat(lang=None): ans = frozenset(ans) if ans is not None else frozenset(data['eng']) except Exception: ans = frozenset((r'A\s+', r'The\s+', r'An\s+')) - ans = '|'.join(ans) - ans = '^(%s)'%ans - try: - ans = re.compile(ans, re.IGNORECASE) - except: - ans = re.compile(r'^(A|The|An)\s+', re.IGNORECASE) + if ans: + ans = '|'.join(ans) + ans = '^(%s)'%ans + try: + ans = re.compile(ans, re.IGNORECASE) + except: + ans = re.compile(r'^(A|The|An)\s+', re.IGNORECASE) + else: + ans = re.compile('^$') # matches only the empty string _title_pats[lang] = ans return ans