Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

actions: Use check_stream_topic when editing message topics.

Alex Vandivereb872b5bcdb8
diff --git a/zerver/lib/actions.py b/zerver/lib/actions.py
index ee4b639339c..1e9b0198ecb 100644
--- a/zerver/lib/actions.py
+++ b/zerver/lib/actions.py
@@ -155,7 +155,7 @@ from zerver.lib.streams import (
send_stream_creation_event,
subscribed_to_stream,
)
-from zerver.lib.string_validation import check_stream_name
+from zerver.lib.string_validation import check_stream_name, check_stream_topic
from zerver.lib.timestamp import datetime_to_timestamp, timestamp_to_datetime
from zerver.lib.timezone import canonicalize_timezone
from zerver.lib.topic import (
@@ -2975,8 +2975,8 @@ def validate_message_edit_payload(
if propagate_mode != "change_one" and topic_name is None and stream_id is None:
raise JsonableError(_("Invalid propagate_mode without topic edit"))
- if topic_name == "":
- raise JsonableError(_("Topic can't be empty"))
+ if topic_name is not None:
+ check_stream_topic(topic_name)
if stream_id is not None and content is not None:
raise JsonableError(_("Cannot change message content while changing stream"))
diff --git a/zerver/tests/test_message_edit.py b/zerver/tests/test_message_edit.py
index df15cd6b45e..95a389df3c3 100644
--- a/zerver/tests/test_message_edit.py
+++ b/zerver/tests/test_message_edit.py
@@ -192,7 +192,21 @@ class EditMessagePayloadTest(EditMessageTestCase):
"topic": " ",
},
)
- self.assert_json_error(result, "Topic can't be empty")
+ self.assert_json_error(result, "Topic can't be empty!")
+
+ def test_edit_message_invalid_topic(self) -> None:
+ self.login("hamlet")
+ msg_id = self.send_stream_message(
+ self.example_user("hamlet"), "Denmark", topic_name="editing", content="before edit"
+ )
+ result = self.client_patch(
+ "/json/messages/" + str(msg_id),
+ {
+ "message_id": msg_id,
+ "topic": "editing\nfun",
+ },
+ )
+ self.assert_json_error(result, "Invalid characters in topic!")
def test_move_message_to_stream_with_content(self) -> None:
(user_profile, old_stream, new_stream, msg_id, msg_id_later) = self.prepare_move_topics(