Skip to content

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

FIX: add missing length validation to chat channel `emoji` (#41465)

Arpit Jalan8ba8ef13d28b
diff --git a/plugins/chat/app/models/chat/channel.rb b/plugins/chat/app/models/chat/channel.rb
index 4f03e4c19dd..88717b2d99d 100644
--- a/plugins/chat/app/models/chat/channel.rb
+++ b/plugins/chat/app/models/chat/channel.rb
@@ -43,6 +43,7 @@ module Chat
validates :chatable_type, length: { maximum: 100 }
validates :type, length: { maximum: 100 }
validates :slug, length: { maximum: 100 }
+ validates :emoji, length: { maximum: 100 }
validate :ensure_slug_ok, if: :slug_changed?
before_validation :generate_auto_slug
diff --git a/plugins/chat/spec/requests/chat/api/channels_controller_spec.rb b/plugins/chat/spec/requests/chat/api/channels_controller_spec.rb
index 36fb16bb297..ecbc434dd10 100644
--- a/plugins/chat/spec/requests/chat/api/channels_controller_spec.rb
+++ b/plugins/chat/spec/requests/chat/api/channels_controller_spec.rb
@@ -530,6 +530,30 @@ RSpec.describe Chat::Api::ChannelsController do
end
end
+ context "when user provides an emoji that is too long" do
+ fab!(:user, :admin)
+ fab!(:channel, :category_channel)
+
+ before { sign_in(user) }
+
+ it "rejects the update" do
+ long_emoji = "a" * 2800
+ expected_error = "Emoji #{I18n.t("errors.messages.too_long", count: 100)}"
+
+ put "/chat/api/channels/#{channel.id}",
+ params: {
+ channel: {
+ emoji: long_emoji,
+ },
+ },
+ as: :json
+
+ expect(response.status).to eq(422)
+ expect(response.parsed_body["errors"]).to contain_exactly(expected_error)
+ expect(channel.reload.emoji).to be_nil
+ end
+ end
+
context "when user provided an empty name" do
fab!(:user, :admin)
fab!(:channel) do