Remove non-BMP characters

This commit is contained in:
mid 2026-02-22 23:42:48 +02:00
parent b896c215ec
commit 8a0449a632

View File

@ -6,6 +6,9 @@ from slixmpp.types import PresenceArgs
import slixmpp.stanza import slixmpp.stanza
import slixmpp.plugins.xep_0084.stanza import slixmpp.plugins.xep_0084.stanza
import base64, time import base64, time
NON_BMP_RE = re.compile(u"[^\U00000000-\U0000d7ff\U0000e000-\U0000ffff]", flags=re.UNICODE)
def non_bmp(s):
return NON_BMP_RE.sub(u'', s)
class GatewayXMPP(ComponentXMPP): class GatewayXMPP(ComponentXMPP):
def __init__(self, plexus, settings, gateway_name, gateway_data): def __init__(self, plexus, settings, gateway_name, gateway_data):
@ -60,6 +63,8 @@ class GatewayXMPP(ComponentXMPP):
# Ignore ours # Ignore ours
return return
nick_name = non_bmp(nick_name)
puppet_data = { puppet_data = {
"identification": identification, "identification": identification,
"jid": f"{hashlib.sha256(str(identification).encode()).hexdigest()[:24]}@{self.pfrom}/mirror", "jid": f"{hashlib.sha256(str(identification).encode()).hexdigest()[:24]}@{self.pfrom}/mirror",
@ -113,6 +118,7 @@ class GatewayXMPP(ComponentXMPP):
puppet_data["queue"].append(queue_callback) puppet_data["queue"].append(queue_callback)
# If the user changed their nickname, try to update it on the puppet # If the user changed their nickname, try to update it on the puppet
nick_name = non_bmp(nick_name)
if nick_name != puppet_data["nicknames"][muc_jid]["nick"]: if nick_name != puppet_data["nicknames"][muc_jid]["nick"]:
assert puppet_data["nicknames"][muc_jid]["state"] == "joined" assert puppet_data["nicknames"][muc_jid]["state"] == "joined"
puppet_data["nicknames"][muc_jid]["state"] = "joining" puppet_data["nicknames"][muc_jid]["state"] = "joining"