From 01b06c90b219dc7eb382e2fa5de16dab61ccc81b Mon Sep 17 00:00:00 2001 From: hsoft Date: Tue, 29 Sep 2009 11:15:36 +0000 Subject: [PATCH] [#60 state:fixed] Ignore invalid regexp in filter field --HG-- extra : convert_revision : svn%3Ac306627e-7827-47d3-bdf0-9a457c9553a1/trunk%40156 --- base/py/results.py | 5 ++++- base/py/tests/results_test.py | 5 +++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/base/py/results.py b/base/py/results.py index dee24920..5b631724 100644 --- a/base/py/results.py +++ b/base/py/results.py @@ -142,8 +142,11 @@ class Results(Markable): else: if not self.__filters: self.__filters = [] + try: + filter_re = re.compile(filter_str, re.IGNORECASE) + except re.error: + return # don't apply this filter. self.__filters.append(filter_str) - filter_re = re.compile(filter_str, re.IGNORECASE) if self.__filtered_dupes is None: self.__filtered_dupes = flatten(g[:] for g in self.groups) self.__filtered_dupes = set(dupe for dupe in self.__filtered_dupes if filter_re.search(dupe.name)) diff --git a/base/py/tests/results_test.py b/base/py/tests/results_test.py index e71e7680..b49303a9 100644 --- a/base/py/tests/results_test.py +++ b/base/py/tests/results_test.py @@ -48,6 +48,11 @@ class TCResultsEmpty(TestCase): def setUp(self): self.results = Results(data) + def test_apply_invalid_filter(self): + # If the applied filter is an invalid regexp, just ignore the filter. + self.results.apply_filter('[') # invalid + self.test_stat_line() # make sure that the stats line isn't saying we applied a '[' filter + def test_stat_line(self): self.assertEqual("0 / 0 (0.00 B / 0.00 B) duplicates marked.",self.results.stat_line)