mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-12-24 19:52:54 +01:00
Various re fixes, including bug #850931.
This commit is contained in:
parent
42e43531fc
commit
fb2d9b7f4f
@ -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.
|
* Fixed bug #851254, Factoids.whatis didn't work on numeric keys.
|
||||||
|
|
||||||
* Added the ability to turn on/off the showing of ids in FunDB
|
* Added the ability to turn on/off the showing of ids in FunDB
|
||||||
|
@ -144,14 +144,13 @@ class Utilities(callbacks.Privmsg):
|
|||||||
except ValueError, e:
|
except ValueError, e:
|
||||||
try:
|
try:
|
||||||
f = utils.perlReToReplacer(regexp)
|
f = utils.perlReToReplacer(regexp)
|
||||||
substitution = True
|
|
||||||
except ValueError, e:
|
except ValueError, e:
|
||||||
irc.error(msg, 'Invalid regexp: %s' % e.args[0])
|
irc.error(msg, 'Invalid regexp: %s' % e.args[0])
|
||||||
return
|
return
|
||||||
if f is None:
|
if f is None:
|
||||||
irc.error(msg, 'Invalid regexp: %s' % e.args[0])
|
irc.error(msg, 'Invalid regexp: %s' % e.args[0])
|
||||||
return
|
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.'
|
s = 'You probably don\'t want to match the empty string.'
|
||||||
irc.error(msg, s)
|
irc.error(msg, s)
|
||||||
else:
|
else:
|
||||||
|
@ -236,7 +236,10 @@ def perlReToReplacer(s):
|
|||||||
(kind, regexp, replace, flags) = nonEscapedSlashes.split(s)
|
(kind, regexp, replace, flags) = nonEscapedSlashes.split(s)
|
||||||
except ValueError: # Unpack list of wrong size.
|
except ValueError: # Unpack list of wrong size.
|
||||||
raise ValueError, 'Must be of the form s/.../.../'
|
raise ValueError, 'Must be of the form s/.../.../'
|
||||||
|
regexp = regexp.replace('\x08', r'\b')
|
||||||
replace = replace.replace('\\/', '/')
|
replace = replace.replace('\\/', '/')
|
||||||
|
for i in xrange(10):
|
||||||
|
replace = replace.replace(chr(i), r'\%s' % i)
|
||||||
if kind != 's':
|
if kind != 's':
|
||||||
raise ValueError, 'Invalid kind: must be "s"'
|
raise ValueError, 'Invalid kind: must be "s"'
|
||||||
g = False
|
g = False
|
||||||
|
@ -76,6 +76,9 @@ class UtilitiesTestCase(PluginTestCase, PluginDocumentation):
|
|||||||
def testReNotEmptyString(self):
|
def testReNotEmptyString(self):
|
||||||
self.assertError('re s//foo/g blah')
|
self.assertError('re s//foo/g blah')
|
||||||
|
|
||||||
|
def testReWorksWithJustCaret(self):
|
||||||
|
self.assertResponse('re s/^/foo/ bar', 'foobar')
|
||||||
|
|
||||||
def testReNoEscapingUnpackListOfWrongSize(self):
|
def testReNoEscapingUnpackListOfWrongSize(self):
|
||||||
self.assertNotRegexp('re foo bar baz', 'unpack list of wrong size')
|
self.assertNotRegexp('re foo bar baz', 'unpack list of wrong size')
|
||||||
|
|
||||||
|
@ -156,6 +156,12 @@ class UtilsTest(unittest.TestCase):
|
|||||||
self.assertEqual(f('CATFISH'), 'dogFISH')
|
self.assertEqual(f('CATFISH'), 'dogFISH')
|
||||||
f = utils.perlReToReplacer('s/foo/foo\/bar/')
|
f = utils.perlReToReplacer('s/foo/foo\/bar/')
|
||||||
self.assertEqual(f('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):
|
def testFindBinaryInPath(self):
|
||||||
if os.name == 'posix':
|
if os.name == 'posix':
|
||||||
|
Loading…
Reference in New Issue
Block a user