Skip to content

A platform for community discussion. Free, open, simple.

FIX: Validate the length of chat draft data (#41548)

Isaac Janzen8ab3d6b90ddd
diff --git a/plugins/chat/app/services/chat/upsert_draft.rb b/plugins/chat/app/services/chat/upsert_draft.rb
index 0930808c596..ba140be2cb4 100644
--- a/plugins/chat/app/services/chat/upsert_draft.rb
+++ b/plugins/chat/app/services/chat/upsert_draft.rb
@@ -30,6 +30,7 @@ module Chat
attribute :data, :string
validates :channel_id, presence: true
+ validates :data, length: { maximum: -> { SiteSetting.max_chat_draft_length } }
end
model :channel
diff --git a/plugins/chat/spec/services/chat/upsert_draft_spec.rb b/plugins/chat/spec/services/chat/upsert_draft_spec.rb
index 2223b86d9ca..0c599d90bee 100644
--- a/plugins/chat/spec/services/chat/upsert_draft_spec.rb
+++ b/plugins/chat/spec/services/chat/upsert_draft_spec.rb
@@ -2,7 +2,10 @@
RSpec.describe Chat::UpsertDraft do
describe described_class::Contract, type: :model do
+ subject(:contract) { described_class.new(channel_id: 1) }
+
it { is_expected.to validate_presence_of :channel_id }
+ it { is_expected.to validate_length_of(:data).is_at_most(SiteSetting.max_chat_draft_length) }
end
describe ".call" do