3
0
mirror of https://github.com/jlu5/PyLink.git synced 2024-11-24 03:29:28 +01:00

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.
This commit is contained in:
James Lu 2019-02-12 14:17:53 -08:00
parent 11b65ee809
commit a9f59307c9

View File

@ -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)