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)
This commit is contained in:
freamon 2024-05-14 20:38:16 +01:00
parent c77a6de126
commit b0f6848312
4 changed files with 5 additions and 5 deletions

View file

@ -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 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, new_message = ChatMessage(sender_id=sender.id, recipient_id=recipient.id, conversation_id=existing_conversation.id,
body=request_json['object']['source']['content'], 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) encrypted=encrypted)
db.session.add(new_message) db.session.add(new_message)
existing_conversation.updated_at = utcnow() existing_conversation.updated_at = utcnow()

View file

@ -938,7 +938,7 @@ def parse_summary(user_json) -> str:
if 'source' in user_json and user_json['source'].get('mediaType') == 'text/markdown': if 'source' in user_json and user_json['source'].get('mediaType') == 'text/markdown':
# Convert Markdown to HTML # Convert Markdown to HTML
markdown_text = user_json['source']['content'] 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 return html_content
elif 'summary' in user_json: elif 'summary' in user_json:
return allowlist_html(user_json['summary']) 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:::' 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: else:
post.body = post_reply.body post.body = post_reply.body
post.body_html = allowlist_html(lemmy_markdown_to_html(post.body) + '\n\n<small><span class="render_username">Generated using AI by: <a href="/u/autotldr@lemmings.world" title="AutoTL;DR">AutoTL;DR</a></span></small>') post.body_html = lemmy_markdown_to_html(post.body) + '\n\n<small><span class="render_username">Generated using AI by: <a href="/u/autotldr@lemmings.world" title="AutoTL;DR">AutoTL;DR</a></span></small>'
db.session.commit() db.session.commit()
return None return None

View file

@ -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: def send_message(message: str, conversation_id: int) -> ChatMessage:
conversation = Conversation.query.get(conversation_id) conversation = Conversation.query.get(conversation_id)
reply = ChatMessage(sender_id=current_user.id, conversation_id=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() conversation.updated_at = utcnow()
db.session.add(reply) db.session.add(reply)
db.session.commit() db.session.commit()

View file

@ -108,7 +108,7 @@ def edit_profile(actor):
if form.password_field.data.strip() != '': if form.password_field.data.strip() != '':
current_user.set_password(form.password_field.data) current_user.set_password(form.password_field.data)
current_user.about = form.about.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.matrix_user_id = form.matrixuserid.data
current_user.bot = form.bot.data current_user.bot = form.bot.data
profile_file = request.files['profile_file'] profile_file = request.files['profile_file']