mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 20:43:39 +08:00
DEV: add maxlength limits to chat messages and revisions (#23530)
Add additional limits to text columns for chat.
This commit is contained in:
parent
b7d7099d08
commit
16ccf30abc
|
@ -73,6 +73,7 @@ module Chat
|
||||||
|
|
||||||
before_save { ensure_last_editor_id }
|
before_save { ensure_last_editor_id }
|
||||||
|
|
||||||
|
validates :cooked, length: { maximum: 20_000 }
|
||||||
validate :validate_message
|
validate :validate_message
|
||||||
|
|
||||||
def self.polymorphic_class_mapping = { "ChatMessage" => Chat::Message }
|
def self.polymorphic_class_mapping = { "ChatMessage" => Chat::Message }
|
||||||
|
|
|
@ -4,6 +4,9 @@ module Chat
|
||||||
class MessageRevision < ActiveRecord::Base
|
class MessageRevision < ActiveRecord::Base
|
||||||
self.table_name = "chat_message_revisions"
|
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 :chat_message, class_name: "Chat::Message"
|
||||||
belongs_to :user
|
belongs_to :user
|
||||||
end
|
end
|
||||||
|
|
6
plugins/chat/spec/models/chat/message_revision_spec.rb
Normal file
6
plugins/chat/spec/models/chat/message_revision_spec.rb
Normal file
|
@ -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
|
|
@ -7,6 +7,12 @@ describe Chat::Message do
|
||||||
|
|
||||||
it { is_expected.to have_many(:chat_mentions).dependent(:destroy) }
|
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
|
describe ".cook" do
|
||||||
it "does not support HTML tags" do
|
it "does not support HTML tags" do
|
||||||
cooked = described_class.cook("<h1>test</h1>")
|
cooked = described_class.cook("<h1>test</h1>")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user