diff options
author | Trygve Aaberge <trygveaa@gmail.com> | 2023-09-16 22:57:19 +0200 |
---|---|---|
committer | Trygve Aaberge <trygveaa@gmail.com> | 2023-09-16 23:09:28 +0200 |
commit | 6478c1410f52183262938daf52bc7e88c062f528 (patch) | |
tree | 2b198562ee2c42b1eed54d0d4740a41f13bb548e | |
parent | 64e1c6fcc13d8eaade4699a3bef778cc1f3094a7 (diff) | |
download | wee-slack-6478c1410f52183262938daf52bc7e88c062f528.tar.gz |
Fix < and > being removed in messages
This fixes a regression in commit 74da303 which caused < and > to be
removed from messages. Escaping them in unfurl_block_element so they can
be unescaped later isn't the nicest fix, but it's the easiest so I'll do
it this way until this is rewritten in the new version.
-rw-r--r-- | wee_slack.py | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/wee_slack.py b/wee_slack.py index 4a69025..0824268 100644 --- a/wee_slack.py +++ b/wee_slack.py @@ -4750,9 +4750,9 @@ def unfurl_rich_text_section(block): def unfurl_block_element(element): if element["type"] == "mrkdwn": - return render_formatting(element["text"]) + return htmlescape(render_formatting(element["text"])) elif element["type"] in ["text", "plain_text"]: - return element["text"] + return htmlescape(element["text"]) elif element["type"] == "image": if element.get("alt_text"): return "{} ({})".format(element["image_url"], element["alt_text"]) @@ -4832,6 +4832,10 @@ def unfurl_refs(text): return re.sub(r"<([^|>]*)(?:\|([^>]*))?>", unfurl_ref, text) +def htmlescape(text): + return text.replace("&", "&").replace("<", "<").replace(">", ">") + + def unhtmlescape(text): return text.replace("<", "<").replace(">", ">").replace("&", "&") |