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 == ' ': if c == ' ':
return c return c
if fg is None: 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) return '\x03%s%s' % (fg, c)
def colorize(self, irc, msg, args, text): def colorize(self, irc, msg, args, text):

View File

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