actions: Use check_stream_topic when editing message topics.

This commit is contained in:
Alex Vandiver
2022-01-11 13:39:17 -08:00
parent 4f482c234c
commit eb872b5bcd
2 changed files with 18 additions and 4 deletions

View File

@@ -155,7 +155,7 @@ from zerver.lib.streams import (
send_stream_creation_event, send_stream_creation_event,
subscribed_to_stream, 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.timestamp import datetime_to_timestamp, timestamp_to_datetime
from zerver.lib.timezone import canonicalize_timezone from zerver.lib.timezone import canonicalize_timezone
from zerver.lib.topic import ( 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: if propagate_mode != "change_one" and topic_name is None and stream_id is None:
raise JsonableError(_("Invalid propagate_mode without topic edit")) raise JsonableError(_("Invalid propagate_mode without topic edit"))
if topic_name == "": if topic_name is not None:
raise JsonableError(_("Topic can't be empty")) check_stream_topic(topic_name)
if stream_id is not None and content is not None: if stream_id is not None and content is not None:
raise JsonableError(_("Cannot change message content while changing stream")) raise JsonableError(_("Cannot change message content while changing stream"))

View File

@@ -192,7 +192,21 @@ class EditMessagePayloadTest(EditMessageTestCase):
"topic": " ", "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: 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( (user_profile, old_stream, new_stream, msg_id, msg_id_later) = self.prepare_move_topics(