From 8ec9324ef12b62d7dbf078eb7070b1c4e0563f48 Mon Sep 17 00:00:00 2001 From: glenvt18 Date: Tue, 14 Jan 2025 03:45:15 +0300 Subject: [PATCH] Fix alias insertion SQLite LIKE operator is case-insensitive. Hence the replacement must be case-insensitive too. If it is not, the keyword found by LIKE might not be replaced and will be found again and again. That will cause unlimited growth of sql_results. Example: https://en.cppreference.com/w/cpp/memory/allocator and Allocator template argument Another option would be using GLOB instead of LIKE for case-sensitive search. Whether it is better or not and search pattern selection is out of scope of this commit. --- cppman/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cppman/main.py b/cppman/main.py index e8c58ae..3a6576e 100644 --- a/cppman/main.py +++ b/cppman/main.py @@ -198,7 +198,7 @@ def rebuild_index(self): % (table, k, k, k, k, k, k)).fetchall() for id, keyword in sql_results: - keyword = keyword.replace("%s" % k, "%s" % a) + keyword = re.sub(re.escape("%s" % k), "%s" % a, keyword, flags=re.IGNORECASE) self.db_cursor.execute( 'INSERT INTO "%s_keywords" (id, keyword) '