From 21cc5837cfcfb237dbfe919b2959656dff25acac Mon Sep 17 00:00:00 2001 From: ingvar1995 Date: Sun, 12 Feb 2017 23:15:33 +0300 Subject: [PATCH] bug fixes with regex --- toxygen/list_items.py | 5 +++-- toxygen/mainscreen_widgets.py | 2 +- toxygen/util.py | 10 ++++++++++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/toxygen/list_items.py b/toxygen/list_items.py index 5a62cb6..ab8d0b4 100644 --- a/toxygen/list_items.py +++ b/toxygen/list_items.py @@ -190,8 +190,9 @@ class MessageItem(QtGui.QWidget): self.message.setFixedHeight(self.height()) self.name.setPixmap(pixmap.scaled(30, 30, QtCore.Qt.KeepAspectRatio, QtCore.Qt.SmoothTransformation)) - def select_text(self, text=''): + def select_text(self, text): tmp = self.message.toHtml() + text = h.escape(text) strings = re.findall(text, tmp, flags=re.IGNORECASE) for s in strings: tmp = self.replace_all(tmp, s) @@ -209,7 +210,7 @@ class MessageItem(QtGui.QWidget): if rgt < lgt: i += rgt + 1 continue - sub = '{}'.format(substring) + sub = '{}'.format(substring) text = text[:i] + sub + text[i + l:] i += len(sub) return text diff --git a/toxygen/mainscreen_widgets.py b/toxygen/mainscreen_widgets.py index 1910cb7..e5b406e 100644 --- a/toxygen/mainscreen_widgets.py +++ b/toxygen/mainscreen_widgets.py @@ -473,7 +473,7 @@ class SearchScreen(QtGui.QWidget): Profile.get_instance().update() text = self.search_text.text() friend = Profile.get_instance().get_curr_friend() - if text and friend: + if text and friend and util.is_re_valid(text): index = friend.search_string(text) self.load_messages(index) diff --git a/toxygen/util.py b/toxygen/util.py index b997873..beeb3a9 100644 --- a/toxygen/util.py +++ b/toxygen/util.py @@ -2,6 +2,7 @@ import os import time import shutil import sys +import re program_version = '0.2.7' @@ -69,6 +70,15 @@ def is_64_bit(): return sys.maxsize > 2 ** 32 +def is_re_valid(regex): + try: + re.compile(regex) + except re.error: + return False + else: + return True + + class Singleton: _instance = None