From 729d1424edc4abb44d2a3fb210895651cd2890ac Mon Sep 17 00:00:00 2001 From: jesopo Date: Thu, 8 Nov 2018 11:37:23 +0000 Subject: [PATCH] Unescape message-tags as per spec Escaping Rules --- src/utils/irc.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/utils/irc.py b/src/utils/irc.py index a128a565..7b82e791 100644 --- a/src/utils/irc.py +++ b/src/utils/irc.py @@ -78,6 +78,13 @@ class IRCLine(object): self.args = args self.has_arbitrary = has_arbitrary +MESSAGE_TAG_ESCAPED = [r"\:", r"\s", r"\\", r"\r", r"\n"] +MESSAGE_TAG_UNESCAPED = [";", " ", "\\", "\r", "\n"] +def message_tag_escape(s): + return _multi_replace(s, MESSAGE_TAG_UNESCAPED, MESSAGE_TAG_ESCAPED) +def message_tag_unescape(s): + return _multi_replace(s, MESSAGE_TAG_ESCAPED, MESSAGE_TAG_UNESCAPED) + def parse_line(line: str) -> IRCLine: tags = {} prefix = typing.Optional[IRCHostmask] @@ -85,6 +92,8 @@ def parse_line(line: str) -> IRCLine: if line[0] == "@": tags_prefix, line = line[1:].split(" ", 1) + tags_prefix = message_tag_unescape(tags_prefix) + if tags_prefix[0] == "{": tags = json.loads(tags_prefix) else: