3
0
mirror of https://github.com/jlu5/PyLink.git synced 2024-11-27 13:09:23 +01:00

relay: whitelist ~ in idents

This commit is contained in:
James Lu 2019-03-20 21:08:55 -07:00
parent c9176a06fc
commit 88f45fb1d5

View File

@ -124,10 +124,11 @@ IRC_ASCII_ALLOWED_CHARS = string.digits + string.ascii_letters + '/^|\\-_[]{}`'
FALLBACK_SEPARATOR = '|'
FALLBACK_CHARACTER = '-'
def _sanitize(text):
def _sanitize(text, extrachars=''):
"""Replaces characters not in IRC_ASCII_ALLOWED_CHARS with FALLBACK_CHARACTER."""
whitelist = IRC_ASCII_ALLOWED_CHARS + extrachars
for char in text:
if char not in IRC_ASCII_ALLOWED_CHARS:
if char not in whitelist:
text = text.replace(char, FALLBACK_CHARACTER)
return text
@ -379,9 +380,13 @@ def spawn_relay_user(irc, remoteirc, user, times_tagged=0, reuse_sid=None):
return
nick = normalize_nick(remoteirc, irc.name, userobj.nick, times_tagged=times_tagged)
# Sanitize UTF8 for networks that don't support it
ident = _sanitize(userobj.ident, extrachars='~')
# Truncate idents at 10 characters, because TS6 won't like them otherwise!
ident = _sanitize(userobj.ident)
ident = ident[:10]
# Normalize hostnames
host = normalize_host(remoteirc, userobj.host)
realname = userobj.realname