diff --git a/src/utils.py b/src/utils.py index ae89259ce..3a5108a42 100755 --- a/src/utils.py +++ b/src/utils.py @@ -211,7 +211,10 @@ def perlReToPythonRe(s): flag |= getattr(re, c) except AttributeError: raise ValueError, 'Invalid flag: %s' % c - return re.compile(regexp, flag) + try: + return re.compile(regexp, flag) + except re.error, e: + raise ValueError, str(e) def perlReToReplacer(s): """Converts a string representation of a Perl regular expression (i.e., diff --git a/test/test_utils.py b/test/test_utils.py index 7a9ac44ee..a3abbc289 100644 --- a/test/test_utils.py +++ b/test/test_utils.py @@ -118,6 +118,7 @@ class UtilsTest(unittest.TestCase): self.failUnless(r.search('/')) r = utils.perlReToPythonRe('m/cat/i') self.failUnless(r.search('CAT')) + self.assertRaises(ValueError, utils.perlReToPythonRe, 'm/?/') def testPerlReToReplacer(self): f = utils.perlReToReplacer('s/foo/bar/')