bug fixes with regex

This commit is contained in:
ingvar1995 2017-02-12 23:15:33 +03:00
parent 150942446d
commit 21cc5837cf
3 changed files with 14 additions and 3 deletions

View File

@ -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 = '<font color="red">{}</font>'.format(substring)
sub = '<font color="red"><b>{}</b></font>'.format(substring)
text = text[:i] + sub + text[i + l:]
i += len(sub)
return text

View File

@ -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)

View File

@ -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