mirror of
https://github.com/discourse/discourse.git
synced 2025-05-30 07:11:34 +08:00
FIX: Do not allow blank chat messages (#21968)
This fixes an issue where a user could send an empty string as a chat message .e.g ' ' and the message would be posted. We don't want this, we need to strip the message first before validating for length etc.
This commit is contained in:
@ -65,6 +65,18 @@ describe Chat::MessageCreator do
|
||||
)
|
||||
end
|
||||
|
||||
it "errors when a blank message is sent" do
|
||||
creator =
|
||||
described_class.create(chat_channel: public_chat_channel, user: user1, content: " ")
|
||||
expect(creator.failed?).to eq(true)
|
||||
expect(creator.error.message).to match(
|
||||
I18n.t(
|
||||
"chat.errors.minimum_length_not_met",
|
||||
{ count: SiteSetting.chat_minimum_message_length },
|
||||
),
|
||||
)
|
||||
end
|
||||
|
||||
it "errors when length is greater than `chat_maximum_message_length`" do
|
||||
SiteSetting.chat_maximum_message_length = 100
|
||||
creator =
|
||||
|
@ -85,6 +85,27 @@ describe Chat::MessageUpdater do
|
||||
expect(chat_message.reload.message).to eq(og_message)
|
||||
end
|
||||
|
||||
it "errors when a blank message is sent" do
|
||||
og_message = "This won't be changed!"
|
||||
chat_message = create_chat_message(user1, og_message, public_chat_channel)
|
||||
new_message = " "
|
||||
|
||||
updater =
|
||||
Chat::MessageUpdater.update(
|
||||
guardian: guardian,
|
||||
chat_message: chat_message,
|
||||
new_content: new_message,
|
||||
)
|
||||
expect(updater.failed?).to eq(true)
|
||||
expect(updater.error.message).to match(
|
||||
I18n.t(
|
||||
"chat.errors.minimum_length_not_met",
|
||||
{ count: SiteSetting.chat_minimum_message_length },
|
||||
),
|
||||
)
|
||||
expect(chat_message.reload.message).to eq(og_message)
|
||||
end
|
||||
|
||||
it "errors if a user other than the message user is trying to edit the message" do
|
||||
og_message = "This won't be changed!"
|
||||
chat_message = create_chat_message(user1, og_message, public_chat_channel)
|
||||
|
Reference in New Issue
Block a user