Various re fixes, including bug #850931.

This commit is contained in:
Jeremy Fincher 2003-12-01 11:06:17 +00:00
parent 42e43531fc
commit fb2d9b7f4f
5 changed files with 16 additions and 2 deletions

View File

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

View File

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

View File

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

View File

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

View File

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