Unescape message-tags as per spec Escaping Rules

This commit is contained in:
jesopo 2018-11-08 11:37:23 +00:00
parent 5e7b335d04
commit 729d1424ed

View file

@ -78,6 +78,13 @@ class IRCLine(object):
self.args = args self.args = args
self.has_arbitrary = has_arbitrary 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: def parse_line(line: str) -> IRCLine:
tags = {} tags = {}
prefix = typing.Optional[IRCHostmask] prefix = typing.Optional[IRCHostmask]
@ -85,6 +92,8 @@ def parse_line(line: str) -> IRCLine:
if line[0] == "@": if line[0] == "@":
tags_prefix, line = line[1:].split(" ", 1) tags_prefix, line = line[1:].split(" ", 1)
tags_prefix = message_tag_unescape(tags_prefix)
if tags_prefix[0] == "{": if tags_prefix[0] == "{":
tags = json.loads(tags_prefix) tags = json.loads(tags_prefix)
else: else: