aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--_pytest/test_linkifytext.py9
-rw-r--r--wee_slack.py10
2 files changed, 14 insertions, 5 deletions
diff --git a/_pytest/test_linkifytext.py b/_pytest/test_linkifytext.py
index f9da3f9..010a48b 100644
--- a/_pytest/test_linkifytext.py
+++ b/_pytest/test_linkifytext.py
@@ -4,3 +4,12 @@ from wee_slack import linkify_text
# linkify_text('@ryan')
# assert False
+
+
+def test_linkifytext_does_partial_html_entity_encoding(mock_weechat, realish_eventrouter):
+ team = realish_eventrouter.teams.values()[0]
+ channel = team.channels.values()[0]
+
+ text = linkify_text('& < > \' "', team, channel)
+
+ assert text == '&amp; &lt; &gt; \' "'
diff --git a/wee_slack.py b/wee_slack.py
index 7bfa4a9..3904ab0 100644
--- a/wee_slack.py
+++ b/wee_slack.py
@@ -1911,7 +1911,7 @@ class SlackMessage(object):
def get_sender(self):
name = ""
name_plain = ""
- if 'bot_id' in self.message_json and self.message_json['bot_id'] is not None:
+ if self.message_json.get('bot_id') in self.team.bots:
name = "{} :]".format(self.team.bots[self.message_json["bot_id"]].formatted_name())
name_plain = "{}".format(self.team.bots[self.message_json["bot_id"]].formatted_name(enable_color=False))
elif 'user' in self.message_json:
@@ -2541,11 +2541,11 @@ def linkify_text(message, team, channel):
.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 a full URL escaping here.
+ # (and should not) perform full HTML entity-encoding here.
# See https://api.slack.com/docs/message-formatting for details.
- .replace('<', '&lt')
- .replace('>', '&gt')
- .replace('&', '&amp')
+ .replace('&', '&amp;')
+ .replace('<', '&lt;')
+ .replace('>', '&gt;')
.split(' '))
for item in enumerate(message):
targets = re.match('^\s*([@#])([\w.-]+[\w. -])(\W*)', item[1])