diff options
| author | 2018-11-08 11:37:23 +0000 | |
|---|---|---|
| committer | 2018-11-08 11:37:23 +0000 | |
| commit | 729d1424edc4abb44d2a3fb210895651cd2890ac (patch) | |
| tree | 13780d7b1da7eda0da1bcd7d3b05d5a088100372 /src | |
| parent | Fix issues that were introduced in message-tag parsing when I added support for (diff) | |
| signature | ||
Unescape message-tags as per spec Escaping Rules
Diffstat (limited to 'src')
| -rw-r--r-- | src/utils/irc.py | 9 |
1 files changed, 9 insertions, 0 deletions
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: |
