Skip to content

Commit

Permalink
ircutils.FormatParser: Make getInt only get integers that are valid c…
Browse files Browse the repository at this point in the history
…olors

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>
  • Loading branch information
jamessan committed Jul 3, 2012
1 parent 786d184 commit a42ab2e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
3 changes: 2 additions & 1 deletion plugins/Filter/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,8 @@ def _color(self, c, fg=None):
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):
Expand Down
17 changes: 12 additions & 5 deletions src/ircutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,11 +410,16 @@ def getInt(self):
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
Expand All @@ -426,6 +431,8 @@ def getColor(self, context):
c = self.getChar()
if c == ',':
context.bg = self.getInt()
else:
self.ungetChar(c)

def wrap(s, length):
processed = []
Expand Down

0 comments on commit a42ab2e

Please sign in to comment.