ircutils.FormatParser: Make getInt only get integers that are valid colors

If a colored message were wrapped just right (e.g., a colored number ending
the chunk), FormatParser would gobble up the color format code and the number
in the message, causing a KeyError when trying to look up the color in
mircColors.

Signed-off-by: James McCoy <jamessan@users.sourceforge.net>
This commit is contained in:
James McCoy 2012-07-02 21:11:50 -04:00
parent 786d184b0a
commit a42ab2e2d4
2 changed files with 14 additions and 6 deletions

View File

@ -357,7 +357,8 @@ class Filter(callbacks.Plugin):
if c == ' ':
return c
if fg is None:
fg = str(random.randint(2, 15)).zfill(2)
fg = random.randint(2, 15)
fg = str(fg).zfill(2)
return '\x03%s%s' % (fg, c)
def colorize(self, irc, msg, args, text):

View File

@ -410,11 +410,16 @@ class FormatParser(object):
i = 0
setI = False
c = self.getChar()
while c.isdigit() and i < 100:
setI = True
i *= 10
i += int(c)
c = self.getChar()
while c.isdigit():
j = i * 10
j += int(c)
if j >= 16:
self.ungetChar(c)
break
else:
setI = True
i = j
c = self.getChar()
self.ungetChar(c)
if setI:
return i
@ -426,6 +431,8 @@ class FormatParser(object):
c = self.getChar()
if c == ',':
context.bg = self.getInt()
else:
self.ungetChar(c)
def wrap(s, length):
processed = []