A platform for community discussion. Free, open, simple.
FIX: Render excerpt HTML for chat replies and edit (#22559)
Martin Brennan4ae26bcaac13
diff --git a/plugins/chat/assets/javascripts/discourse/components/chat-composer-message-details.hbs b/plugins/chat/assets/javascripts/discourse/components/chat-composer-message-details.hbsindex 43122bfb7f1..5b5a10eedc7 100644--- a/plugins/chat/assets/javascripts/discourse/components/chat-composer-message-details.hbs+++ b/plugins/chat/assets/javascripts/discourse/components/chat-composer-message-details.hbs@@ -8,7 +8,7 @@<Chat::UserAvatar @user={{@message.user}} /><span class="chat-reply__username">{{@message.user.username}}</span><span class="chat-reply__excerpt">- {{replace-emoji @message.excerpt}}+ {{replace-emoji (html-safe @message.excerpt)}}</span></div>diff --git a/plugins/chat/assets/javascripts/discourse/components/chat-message-in-reply-to-indicator.hbs b/plugins/chat/assets/javascripts/discourse/components/chat-message-in-reply-to-indicator.hbsindex 0ad871a1398..716525f3fd1 100644--- a/plugins/chat/assets/javascripts/discourse/components/chat-message-in-reply-to-indicator.hbs+++ b/plugins/chat/assets/javascripts/discourse/components/chat-message-in-reply-to-indicator.hbs@@ -13,7 +13,7 @@{{/if}}<span class="chat-reply__excerpt">- {{replace-emoji @message.inReplyTo.excerpt}}+ {{replace-emoji (html-safe @message.inReplyTo.excerpt)}}</span></LinkTo>{{/if}}\ No newline at end of filediff --git a/plugins/chat/spec/system/chat/composer/channel_spec.rb b/plugins/chat/spec/system/chat/composer/channel_spec.rbindex 0f6980ca6a1..92d2630bee5 100644--- a/plugins/chat/spec/system/chat/composer/channel_spec.rb+++ b/plugins/chat/spec/system/chat/composer/channel_spec.rb@@ -24,7 +24,7 @@ RSpec.describe "Chat | composer | channel", type: :system, js: true doexpect(channel_page.composer.message_details).to have_message(id: message_1.id,- exact_text: "<mark>not marked</mark>",+ exact_text: "<mark>not marked</mark>",)enddiff --git a/plugins/chat/spec/system/chat_channel_spec.rb b/plugins/chat/spec/system/chat_channel_spec.rbindex 483cda9d265..6be6c217969 100644--- a/plugins/chat/spec/system/chat_channel_spec.rb+++ b/plugins/chat/spec/system/chat_channel_spec.rb@@ -241,7 +241,17 @@ RSpec.describe "Chat channel", type: :system dochat.visit_channel(channel_1)expect(find(".chat-reply .chat-reply__excerpt")["innerHTML"].strip).to eq(- "&lt;mark&gt;not marked&lt;/mark&gt;",+ "<mark>not marked</mark>",+ )+ end++ it "renders safe HTML like mentions (which are just links) in the reply-to" do+ message_2.update!(message: "@#{other_user.username} <mark>not marked</mark>")+ message_2.rebake!+ chat.visit_channel(channel_1)++ expect(find(".chat-reply .chat-reply__excerpt")["innerHTML"].strip).to eq(+ "<a class=\"mention\" href=\"/u/#{other_user.username}\">@#{other_user.username}</a> <mark>not marked</mark>",)endenddiff --git a/plugins/chat/spec/system/chat_composer_draft_spec.rb b/plugins/chat/spec/system/chat_composer_draft_spec.rbindex d3a3700dda3..a0c254f8d6c 100644--- a/plugins/chat/spec/system/chat_composer_draft_spec.rb+++ b/plugins/chat/spec/system/chat_composer_draft_spec.rb@@ -3,7 +3,13 @@RSpec.describe "Chat composer draft", type: :system dofab!(:current_user) { Fabricate(:user) }fab!(:channel_1) { Fabricate(:chat_channel) }- fab!(:message_1) { Fabricate(:chat_message, chat_channel: channel_1) }+ fab!(:message_1) do+ Fabricate(+ :chat_message,+ chat_channel: channel_1,+ message: "This is a message for draft and replies",+ )+ endlet(:chat_page) { PageObjects::Pages::Chat.new }let(:channel_page) { PageObjects::Pages::ChatChannel.new }diff --git a/plugins/chat/spec/system/reply_to_message/drawer_spec.rb b/plugins/chat/spec/system/reply_to_message/drawer_spec.rbindex 89f4bab3138..6e37b9700b7 100644--- a/plugins/chat/spec/system/reply_to_message/drawer_spec.rb+++ b/plugins/chat/spec/system/reply_to_message/drawer_spec.rb@@ -9,7 +9,12 @@ RSpec.describe "Reply to message - channel - drawer", type: :system dofab!(:current_user) { Fabricate(:user) }fab!(:channel_1) { Fabricate(:category_channel) }fab!(:original_message) do- Fabricate(:chat_message, chat_channel: channel_1, user: Fabricate(:user))+ Fabricate(+ :chat_message,+ chat_channel: channel_1,+ user: Fabricate(:user),+ message: "This is a message to reply to!",+ )endbefore dodiff --git a/plugins/chat/spec/system/reply_to_message/full_page_spec.rb b/plugins/chat/spec/system/reply_to_message/full_page_spec.rbindex f7ec6a392ab..fcc1a9772b8 100644--- a/plugins/chat/spec/system/reply_to_message/full_page_spec.rb+++ b/plugins/chat/spec/system/reply_to_message/full_page_spec.rb@@ -9,7 +9,12 @@ RSpec.describe "Reply to message - channel - full page", type: :system dofab!(:current_user) { Fabricate(:user) }fab!(:channel_1) { Fabricate(:category_channel) }fab!(:original_message) do- Fabricate(:chat_message, chat_channel: channel_1, user: Fabricate(:user))+ Fabricate(+ :chat_message,+ chat_channel: channel_1,+ user: Fabricate(:user),+ message: "This is a message to reply to!",+ )endbefore do@@ -100,5 +105,22 @@ RSpec.describe "Reply to message - channel - full page", type: :system doexpect(channel_page).to have_message(text: "reply to message")end++ it "renders safe HTML from the original message excerpt" do+ other_user = Fabricate(:user)+ original_message.update!(message: "@#{other_user.username} <mark>not marked</mark>")+ original_message.rebake!+ chat_page.visit_channel(channel_1)+ channel_page.reply_to(original_message)++ expect(find(".chat-reply .chat-reply__excerpt")["innerHTML"].strip).to eq(+ "<a class=\"mention\" href=\"/u/#{other_user.username}\">@#{other_user.username}</a> <mark>not marked</mark>",+ )++ channel_page.fill_composer("reply to message")+ channel_page.click_send_message++ expect(channel_page).to have_message(text: "reply to message")+ endendenddiff --git a/plugins/chat/spec/system/reply_to_message/mobile_spec.rb b/plugins/chat/spec/system/reply_to_message/mobile_spec.rbindex 345dbdb28ab..089b08314bc 100644--- a/plugins/chat/spec/system/reply_to_message/mobile_spec.rb+++ b/plugins/chat/spec/system/reply_to_message/mobile_spec.rb@@ -9,7 +9,12 @@ RSpec.describe "Reply to message - channel - mobile", type: :system, mobile: trufab!(:current_user) { Fabricate(:user) }fab!(:channel_1) { Fabricate(:category_channel) }fab!(:original_message) do- Fabricate(:chat_message, chat_channel: channel_1, user: Fabricate(:user))+ Fabricate(+ :chat_message,+ chat_channel: channel_1,+ user: Fabricate(:user),+ message: "This is a message to reply to!",+ )endbefore do