diff options
author | Trygve Aaberge <trygveaa@gmail.com> | 2021-02-21 14:21:28 +0100 |
---|---|---|
committer | Trygve Aaberge <trygveaa@gmail.com> | 2021-02-21 14:23:20 +0100 |
commit | 21e1bc6dc3a3d12880b9430675e54dad6b41bd77 (patch) | |
tree | 9c44571857c5ecc862c7aef8702c78dc6aedc0c8 | |
parent | 101518f0d3a790c775cc2123675ae17bf6b04fc2 (diff) | |
download | wee-slack-21e1bc6dc3a3d12880b9430675e54dad6b41bd77.tar.gz |
Don't escape <>& in me messages
Apparently chat.meMessage requires these characters unescaped, even
though it interpret links using these characters. There doesn't seem to
be any options for changing this behavior, so we have to linkify
nicks/channels while also leaving <>& unescaped.
Fixes #704, closes #822
-rw-r--r-- | wee_slack.py | 30 |
1 files changed, 16 insertions, 14 deletions
diff --git a/wee_slack.py b/wee_slack.py index b5714f7..33a9c11 100644 --- a/wee_slack.py +++ b/wee_slack.py @@ -1615,11 +1615,12 @@ class SlackChannelCommon(object): self.print_getting_history() def send_message(self, message, subtype=None, request_dict_ext={}): - message = linkify_text(message, self.team) if subtype == 'me_message': + message = linkify_text(message, self.team, escape_characters=False) s = SlackRequest(self.team, "chat.meMessage", {"channel": self.identifier, "text": message}, channel=self) self.eventrouter.receive(s) else: + message = linkify_text(message, self.team) request = {"type": "message", "channel": self.identifier, "text": message, "user": self.team.myidentifier} request.update(request_dict_ext) @@ -3643,23 +3644,24 @@ def render_formatting(text): return text -def linkify_text(message, team, only_users=False): +def linkify_text(message, team, only_users=False, escape_characters=True): # The get_username_map function is a bit heavy, but this whole # function is only called on message send.. usernames = team.get_username_map() channels = team.get_channel_map() usergroups = team.generate_usergroup_map() - message_escaped = (message - # Replace IRC formatting chars with Slack formatting chars. - .replace('\x02', '*') - .replace('\x1D', '_') - .replace('\x1F', config.map_underline_to) - # Escape chars that have special meaning to Slack. Note that we do not - # (and should not) perform full HTML entity-encoding here. - # See https://api.slack.com/docs/message-formatting for details. - .replace('&', '&') - .replace('<', '<') - .replace('>', '>')) + if escape_characters: + message = (message + # Replace IRC formatting chars with Slack formatting chars. + .replace('\x02', '*') + .replace('\x1D', '_') + .replace('\x1F', config.map_underline_to) + # Escape chars that have special meaning to Slack. Note that we do not + # (and should not) perform full HTML entity-encoding here. + # See https://api.slack.com/docs/message-formatting for details. + .replace('&', '&') + .replace('<', '<') + .replace('>', '>')) def linkify_word(match): word = match.group(0) @@ -3677,7 +3679,7 @@ def linkify_text(message, team, only_users=False): return word linkify_regex = r'(?:^|(?<=\s))([@#])([\w\(\)\'.-]+)' - return re.sub(linkify_regex, linkify_word, message_escaped, flags=re.UNICODE) + return re.sub(linkify_regex, linkify_word, message, flags=re.UNICODE) def unfurl_blocks(blocks): |