From 6478c1410f52183262938daf52bc7e88c062f528 Mon Sep 17 00:00:00 2001 From: Trygve Aaberge Date: Sat, 16 Sep 2023 22:57:19 +0200 Subject: 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. --- wee_slack.py | 8 ++++++-- 1 file 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("&", "&") -- cgit