Skip to content

Commit

Permalink
Fix < and > being removed in messages
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
trygveaa committed Sep 16, 2023
1 parent 64e1c6f commit 6478c14
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions wee_slack.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
Expand Down Expand Up @@ -4832,6 +4832,10 @@ def unfurl_ref(match):
return re.sub(r"<([^|>]*)(?:\|([^>]*))?>", unfurl_ref, text)


def htmlescape(text):
return text.replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;")


def unhtmlescape(text):
return text.replace("&lt;", "<").replace("&gt;", ">").replace("&amp;", "&")

Expand Down

0 comments on commit 6478c14

Please sign in to comment.