Skip to content

Commit

Permalink
Merge #250: fix crash on IRC notice with non-ascii characters
Browse files Browse the repository at this point in the history
9ce9ee5 fix encode crash on irc notice (undeath)
  • Loading branch information
AdamISZ committed Dec 15, 2018
2 parents d7a2b6b + 9ce9ee5 commit bcc662c
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions jmdaemon/jmdaemon/irc.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,20 @@
def wlog(*x):
"""Simplifier to add lists to the debug log
"""
def conv(s):
# note: this only works because of the future package
if isinstance(s, str):
return s
elif isinstance(s, bytes):
return s.decode('utf-8', errors='ignore')
else:
return str(s)

if x[0] == "WARNING":
msg = " ".join([str(a) for a in x[1:]])
msg = " ".join([conv(a) for a in x[1:]])
log.warn(msg)
else:
msg = " ".join([str(a) for a in x])
msg = " ".join([conv(a) for a in x])
log.debug(msg)

def get_irc_text(line):
Expand Down Expand Up @@ -402,4 +411,4 @@ def left(self, channel):
#wlog('(unhandled) left: ', channel)

def noticed(self, user, channel, message):
wlog('(unhandled) noticed: ', user, channel, message)
wlog('(unhandled) noticed: ', user, channel, message)

0 comments on commit bcc662c

Please sign in to comment.