diff --git a/plugins/chat/app/models/chat/message.rb b/plugins/chat/app/models/chat/message.rb index 5ba54f666b6..965c2fa09a3 100644 --- a/plugins/chat/app/models/chat/message.rb +++ b/plugins/chat/app/models/chat/message.rb @@ -73,6 +73,7 @@ module Chat before_save { ensure_last_editor_id } + validates :cooked, length: { maximum: 20_000 } validate :validate_message def self.polymorphic_class_mapping = { "ChatMessage" => Chat::Message } diff --git a/plugins/chat/app/models/chat/message_revision.rb b/plugins/chat/app/models/chat/message_revision.rb index 3b01ee03339..8a273443e1a 100644 --- a/plugins/chat/app/models/chat/message_revision.rb +++ b/plugins/chat/app/models/chat/message_revision.rb @@ -4,6 +4,9 @@ module Chat class MessageRevision < ActiveRecord::Base self.table_name = "chat_message_revisions" + validates :old_message, length: { maximum: 50_000 } + validates :new_message, length: { maximum: 50_000 } + belongs_to :chat_message, class_name: "Chat::Message" belongs_to :user end diff --git a/plugins/chat/spec/models/chat/message_revision_spec.rb b/plugins/chat/spec/models/chat/message_revision_spec.rb new file mode 100644 index 00000000000..b5e4bba527d --- /dev/null +++ b/plugins/chat/spec/models/chat/message_revision_spec.rb @@ -0,0 +1,6 @@ +# frozen_string_literal: true + +RSpec.describe Chat::MessageRevision do + it { is_expected.to validate_length_of(:old_message).is_at_most(50_000) } + it { is_expected.to validate_length_of(:new_message).is_at_most(50_000) } +end diff --git a/plugins/chat/spec/models/chat/message_spec.rb b/plugins/chat/spec/models/chat/message_spec.rb index 7b44fa94271..5c4b0fb974d 100644 --- a/plugins/chat/spec/models/chat/message_spec.rb +++ b/plugins/chat/spec/models/chat/message_spec.rb @@ -7,6 +7,12 @@ describe Chat::Message do it { is_expected.to have_many(:chat_mentions).dependent(:destroy) } + describe "validations" do + subject(:message) { described_class.new(message: "") } + + it { is_expected.to validate_length_of(:cooked).is_at_most(20_000) } + end + describe ".cook" do it "does not support HTML tags" do cooked = described_class.cook("