Blame SOURCES/BZ-1096147-history-search-crash.patch

5e9bef
commit 5efc1e1b88398da7f89dcb9055d62481bb288a8a
5e9bef
Author: James Antill <james@and.org>
5e9bef
Date:   Tue Sep 16 16:33:33 2014 -0400
5e9bef
5e9bef
    Workaround history searching for [abc] character lists failures. BZ 1096147.
5e9bef
5e9bef
diff --git a/yum/history.py b/yum/history.py
5e9bef
index 2f423d9..fd80191 100644
5e9bef
--- a/yum/history.py
5e9bef
+++ b/yum/history.py
5e9bef
@@ -20,6 +20,7 @@
5e9bef
 import time
5e9bef
 import os, os.path
5e9bef
 import glob
5e9bef
+import re
5e9bef
 from weakref import proxy as weakref
5e9bef
 
5e9bef
 from sqlutils import sqlite, executeSQL, sql_esc_glob
5e9bef
@@ -1422,6 +1423,17 @@ class YumHistory:
5e9bef
         if cur is None:
5e9bef
             return set()
5e9bef
 
5e9bef
+        #  This is kind of a hack, we can't do 'y[u]m' in SQL. In real yum
5e9bef
+        # we manually load everything and then do it inside yum (which is slow
5e9bef
+        # and a lot of code, but nobody uses it anyway and we already had the
5e9bef
+        # code). Here we don't have the code though, and still nobody will use
5e9bef
+        # it. So we cheat:
5e9bef
+        #  1. Convert 'y[u]m' into 'y?m' ... it returns more answers than it
5e9bef
+        #     should, but the correct answers are there.
5e9bef
+        #  2. Convert 'y[m' info 'y!m' ... neither will match anything, so w/e.
5e9bef
+        patterns = [re.sub('\[[^]]+\]', '?', x).replace('[', '!')
5e9bef
+                    for x in patterns]
5e9bef
+
5e9bef
         data = _setupHistorySearchSQL(patterns, ignore_case)
5e9bef
         (need_full, npatterns, fields, names) = data
5e9bef