From b0f68483129cfcda94e3fafb491e9b4fe8566ab6 Mon Sep 17 00:00:00 2001 From: freamon Date: Tue, 14 May 2024 20:38:16 +0100 Subject: [PATCH] Avoid invoking allowlist_html() twice (markdown_to_html() already returns the output from that function) (autotldr username html isn't passed to allowlist_list to avoid getting a target=_blank attribute) --- app/activitypub/routes.py | 2 +- app/activitypub/util.py | 4 ++-- app/chat/util.py | 2 +- app/user/routes.py | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/activitypub/routes.py b/app/activitypub/routes.py index 459fd67e..04540049 100644 --- a/app/activitypub/routes.py +++ b/app/activitypub/routes.py @@ -474,7 +474,7 @@ def process_inbox_request(request_json, activitypublog_id, ip_address): encrypted = request_json['object']['encrypted'] if 'encrypted' in request_json['object'] else None new_message = ChatMessage(sender_id=sender.id, recipient_id=recipient.id, conversation_id=existing_conversation.id, body=request_json['object']['source']['content'], - body_html=allowlist_html(lemmy_markdown_to_html(request_json['object']['source']['content'])), + body_html=lemmy_markdown_to_html(request_json['object']['source']['content']), encrypted=encrypted) db.session.add(new_message) existing_conversation.updated_at = utcnow() diff --git a/app/activitypub/util.py b/app/activitypub/util.py index d2d6d109..de6c2fc2 100644 --- a/app/activitypub/util.py +++ b/app/activitypub/util.py @@ -938,7 +938,7 @@ def parse_summary(user_json) -> str: if 'source' in user_json and user_json['source'].get('mediaType') == 'text/markdown': # Convert Markdown to HTML markdown_text = user_json['source']['content'] - html_content = allowlist_html(lemmy_markdown_to_html(markdown_text)) + html_content = lemmy_markdown_to_html(markdown_text) return html_content elif 'summary' in user_json: return allowlist_html(user_json['summary']) @@ -1362,7 +1362,7 @@ def create_post_reply(activity_log: ActivityPubLog, community: Community, in_rep post.body = "🤖 I'm a bot that provides automatic summaries for articles:\n::: spoiler Click here to see the summary\n" + post_reply.body + '\n:::' else: post.body = post_reply.body - post.body_html = allowlist_html(lemmy_markdown_to_html(post.body) + '\n\nGenerated using AI by: AutoTL;DR') + post.body_html = lemmy_markdown_to_html(post.body) + '\n\nGenerated using AI by: AutoTL;DR' db.session.commit() return None diff --git a/app/chat/util.py b/app/chat/util.py index 4f5114b9..d997e181 100644 --- a/app/chat/util.py +++ b/app/chat/util.py @@ -12,7 +12,7 @@ from app.utils import allowlist_html, shorten_string, gibberish, markdown_to_htm def send_message(message: str, conversation_id: int) -> ChatMessage: conversation = Conversation.query.get(conversation_id) reply = ChatMessage(sender_id=current_user.id, conversation_id=conversation.id, - body=message, body_html=allowlist_html(markdown_to_html(message))) + body=message, body_html=markdown_to_html(message)) conversation.updated_at = utcnow() db.session.add(reply) db.session.commit() diff --git a/app/user/routes.py b/app/user/routes.py index dc84fb0c..c1b75d9c 100644 --- a/app/user/routes.py +++ b/app/user/routes.py @@ -108,7 +108,7 @@ def edit_profile(actor): if form.password_field.data.strip() != '': current_user.set_password(form.password_field.data) current_user.about = form.about.data - current_user.about_html = allowlist_html(markdown_to_html(form.about.data)) + current_user.about_html = markdown_to_html(form.about.data) current_user.matrix_user_id = form.matrixuserid.data current_user.bot = form.bot.data profile_file = request.files['profile_file']