diff --git a/plugins/chat/app/models/chat/message.rb b/plugins/chat/app/models/chat/message.rb index 1e92d77f931..1e03efc2db4 100644 --- a/plugins/chat/app/models/chat/message.rb +++ b/plugins/chat/app/models/chat/message.rb @@ -122,7 +122,14 @@ module Chat def build_excerpt # just show the URL if the whole message is a URL, because we cannot excerpt oneboxes - return message if UrlHelper.relaxed_parse(message).is_a?(URI) + urls = PrettyText.extract_links(cooked).map(&:url) + if urls.present? + regex = %r{^[^:]+://} + clean_urls = urls.map { |url| url.sub(regex, "") } + if message.gsub(regex, "").split.sort == clean_urls.sort + return PrettyText.excerpt(urls.join(" "), EXCERPT_LENGTH) + end + end # upload-only messages are better represented as the filename return uploads.first.original_filename if cooked.blank? && uploads.present? diff --git a/plugins/chat/spec/system/chat_channel_spec.rb b/plugins/chat/spec/system/chat_channel_spec.rb index 08583ac896b..64040cc1005 100644 --- a/plugins/chat/spec/system/chat_channel_spec.rb +++ b/plugins/chat/spec/system/chat_channel_spec.rb @@ -296,6 +296,15 @@ RSpec.describe "Chat channel", type: :system do ) end + it "renders escaped HTML when including a #" do + update_message!(message_2, user: other_user, text: "#general not abbr") + chat_page.visit_channel(channel_1) + + expect(find(".chat-reply .chat-reply__excerpt")["innerHTML"].strip).to eq( + "#general <abbr>not abbr</abbr>", + ) + end + it "renders safe HTML like mentions (which are just links) in the reply-to" do update_message!( message_2,