diff --git a/irctokens/protocol.py b/irctokens/protocol.py index 12b0dbe..1f4eb3a 100644 --- a/irctokens/protocol.py +++ b/irctokens/protocol.py @@ -4,6 +4,8 @@ TAG_UNESCAPED = ["\\", " ", ";", "\r", "\n"] TAG_ESCAPED = ["\\\\", "\\s", "\\:", "\\r", "\\n"] def _unescape_tag(value: str): + if value.endswith("\\") and not value.endswith("\\\\"): + value = value[:-1] parts = value.split("\\\\") for i, piece in enumerate(TAG_ESCAPED): for j, part in enumerate(parts): diff --git a/test/tokenise.py b/test/tokenise.py index 76cf211..851fa25 100644 --- a/test/tokenise.py +++ b/test/tokenise.py @@ -22,6 +22,10 @@ class TokenTestTags(unittest.TestCase): line = irctokens.tokenise(r"@id=1\\\s\\s PRIVMSG #channel") self.assertEqual(line.tags["id"], "1\\ \\s") + def test_lone_end_slash(self): + line = irctokens.tokenise("@id=1\\ PRIVMSG #channel") + self.assertEqual(line.tags["id"], "1") + class TokenTestSource(unittest.TestCase): def test_without_tags(self): line = irctokens.tokenise(":nick!user@host PRIVMSG #channel")