diff --git a/ChangeLog b/ChangeLog index de9da043b..51c888f9c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ + * Fixed bug #850931 as well as several other minor bugs in + Utilities.re. + * Fixed bug #851254, Factoids.whatis didn't work on numeric keys. * Added the ability to turn on/off the showing of ids in FunDB diff --git a/plugins/Utilities.py b/plugins/Utilities.py index 019c31a73..4e07ca02d 100644 --- a/plugins/Utilities.py +++ b/plugins/Utilities.py @@ -144,14 +144,13 @@ class Utilities(callbacks.Privmsg): except ValueError, e: try: f = utils.perlReToReplacer(regexp) - substitution = True except ValueError, e: irc.error(msg, 'Invalid regexp: %s' % e.args[0]) return if f is None: irc.error(msg, 'Invalid regexp: %s' % e.args[0]) return - if f(''): # It matches the empty string. + if f('') and len(f(' ')) > len(f(''))+1: # Matches the empty string. s = 'You probably don\'t want to match the empty string.' irc.error(msg, s) else: diff --git a/src/utils.py b/src/utils.py index ca9ab4132..376788c71 100755 --- a/src/utils.py +++ b/src/utils.py @@ -236,7 +236,10 @@ def perlReToReplacer(s): (kind, regexp, replace, flags) = nonEscapedSlashes.split(s) except ValueError: # Unpack list of wrong size. raise ValueError, 'Must be of the form s/.../.../' + regexp = regexp.replace('\x08', r'\b') replace = replace.replace('\\/', '/') + for i in xrange(10): + replace = replace.replace(chr(i), r'\%s' % i) if kind != 's': raise ValueError, 'Invalid kind: must be "s"' g = False diff --git a/test/test_Utilities.py b/test/test_Utilities.py index 421407503..27b15d8c2 100644 --- a/test/test_Utilities.py +++ b/test/test_Utilities.py @@ -76,6 +76,9 @@ class UtilitiesTestCase(PluginTestCase, PluginDocumentation): def testReNotEmptyString(self): self.assertError('re s//foo/g blah') + def testReWorksWithJustCaret(self): + self.assertResponse('re s/^/foo/ bar', 'foobar') + def testReNoEscapingUnpackListOfWrongSize(self): self.assertNotRegexp('re foo bar baz', 'unpack list of wrong size') diff --git a/test/test_utils.py b/test/test_utils.py index ac2bf9227..618a4705a 100644 --- a/test/test_utils.py +++ b/test/test_utils.py @@ -156,6 +156,12 @@ class UtilsTest(unittest.TestCase): self.assertEqual(f('CATFISH'), 'dogFISH') f = utils.perlReToReplacer('s/foo/foo\/bar/') self.assertEqual(f('foo'), 'foo/bar') + f = utils.perlReToReplacer('s/^/foo/') + self.assertEqual(f('bar'), 'foobar') + + def testPerlReToReplacerBug850931(self): + f = utils.perlReToReplacer('s/\b(\w+)\b/\1./g') + self.assertEqual(f('foo bar baz'), 'foo. bar. baz.') def testFindBinaryInPath(self): if os.name == 'posix':