From a9f59307c9a7345af4cd78b46736e83d8dc28116 Mon Sep 17 00:00:00 2001 From: James Lu Date: Tue, 12 Feb 2019 14:17:53 -0800 Subject: [PATCH] relay: use base64 as fallback if unidecode returns an empty string for nick This is the case for e.g. nicks that are only an emoji. --- plugins/relay.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/plugins/relay.py b/plugins/relay.py index 608820a..c5fcc5f 100644 --- a/plugins/relay.py +++ b/plugins/relay.py @@ -4,6 +4,7 @@ import threading import string from collections import defaultdict import inspect +import base64 from pylinkirc import utils, world, conf, structures from pylinkirc.log import log @@ -132,8 +133,16 @@ def normalize_nick(irc, netname, nick, times_tagged=0, uid=''): """ is_unicode_capable = irc.casemapping in ('utf8', 'utf-8', 'rfc7700') if USE_UNIDECODE and not is_unicode_capable: - nick = unidecode.unidecode(nick) - netname = unidecode.unidecode(netname) + decoded_nick = unidecode.unidecode(nick).strip() + netname = unidecode.unidecode(netname).strip() + if decoded_nick: + nick = decoded_nick + else: + # XXX: The decoded version of the nick is empty, YUCK! + # Base64 the nick for now, since (interestingly) we don't enforce UIDs to always be + # ASCII strings. + nick = base64.b64encode(nick.encode(irc.encoding, 'replace'), altchars=b'-_') + nick = nick.decode() # Normalize spaces to hyphens nick = nick.replace(' ', FALLBACK_CHARACTER)