From 681bd5d85d292f1350db51506710705bcca135ed Mon Sep 17 00:00:00 2001 From: Valentin Lorentz Date: Wed, 4 Feb 2015 17:31:42 +0100 Subject: [PATCH] Count number of bytes instead of number of characters for truncating messages. Closes GH-1038. --- src/callbacks.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/callbacks.py b/src/callbacks.py index c336eb1fc..a0524a20c 100644 --- a/src/callbacks.py +++ b/src/callbacks.py @@ -926,7 +926,13 @@ class NestedCommandsIrcProxy(ReplyIrcProxy): # In case we're truncating, we add 20 to allowedLength, # because our allowedLength is shortened for the # "(XX more messages)" trailer. - s = s[:allowedLength+len(_('(XX more messages)'))] + if sys.version_info[0] >= 3: + appended = _('(XX more messages)').encode() + s = s.encode()[:allowedLength+len(appended)] + s = s.decode('utf8', 'ignore') + else: + appended = _('(XX more messages)') + s = s[:allowedLength+len(appended)] # There's no need for action=self.action here because # action implies noLengthCheck, which has already been # handled. Let's stick an assert in here just in case.