Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
reminders: Stop interpolating user-provided values in format string.
Alex Vandiver575dd10f996b
diff --git a/zerver/lib/reminders.py b/zerver/lib/reminders.pyindex f1cbccb20b2..9eb9f4f9707 100644--- a/zerver/lib/reminders.py+++ b/zerver/lib/reminders.py@@ -88,11 +88,12 @@ def get_reminder_formatted_content(content += "\n"fence = get_unused_fence(content)quoted_message = "{fence}quote\n{msg_content}\n{fence}"- content += quoted_message- length_without_message_content = len(content.format(fence=fence, msg_content=""))+ length_without_message_content = len(+ content + quoted_message.format(fence=fence, msg_content="")+ )max_length = settings.MAX_MESSAGE_LENGTH - length_without_message_contentmsg_content = truncate_content(message.content, max_length, "\n[message truncated]")- content = content.format(+ content += quoted_message.format(fence=fence,msg_content=msg_content,)diff --git a/zerver/tests/test_reminders.py b/zerver/tests/test_reminders.pyindex 0d4613ac15b..7b22b3334b3 100644--- a/zerver/tests/test_reminders.py+++ b/zerver/tests/test_reminders.py@@ -463,3 +463,20 @@ class RemindersTest(ZulipTestCase):f"Maximum reminder note length: {len(note) - 1} characters",status_code=400,)++ # Test with note containing formatting characters+ note = "{123}"+ content = "{456}"+ message_id = self.send_stream_message(+ self.example_user("hamlet"), "Verona", content, topic_name="{789}"+ )+ result = self.do_schedule_reminder(message_id, scheduled_delivery_timestamp, note)+ self.assert_json_success(result)+ scheduled_message = self.last_scheduled_reminder()+ self.assertEqual(+ scheduled_message.content,+ "You requested a reminder for #**Verona>{789}@"+ + str(message_id)+ + "**. Note:\n > {123}\n\n"+ f"@_**King Hamlet|10** [said](http://zulip.testserver/#narrow/channel/3-Verona/topic/.7B789.7D/near/{message_id}):\n```quote\n{content}\n```",+ )