From dfe840f71dc53a7d18299d764154f6170c4bdf47 Mon Sep 17 00:00:00 2001 From: Joffrey JAFFEUX Date: Mon, 9 Oct 2023 08:30:18 +0200 Subject: [PATCH] FIX: properly create a mention when followed by dots (#23829) At the moment writing a mention similar to `@bob...hi` would have resulted in chat trying to find a user named `bob...hi` which would fail. This was due to the `replacements` rule not being present in the rules used to cook chat messages. We are still missing few default rules like: normalize, smartquotes, text_join, ... which don't seem to be necessary but could be added if we found a reason for. More info at: https://github.com/markdown-it/markdown-it/blob/e476f78bc3ea3576beb61bdc94322d0a6b2d85cc/lib/parser_core.js --- plugins/chat/app/models/chat/message.rb | 1 + plugins/chat/spec/models/chat/message_spec.rb | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/plugins/chat/app/models/chat/message.rb b/plugins/chat/app/models/chat/message.rb index fe1e7bd7b6a..e81edec3fe4 100644 --- a/plugins/chat/app/models/chat/message.rb +++ b/plugins/chat/app/models/chat/message.rb @@ -211,6 +211,7 @@ module Chat strikethrough blockquote emphasis + replacements ] def self.cook(message, opts = {}) diff --git a/plugins/chat/spec/models/chat/message_spec.rb b/plugins/chat/spec/models/chat/message_spec.rb index 93158296a9d..9ad53bcf44e 100644 --- a/plugins/chat/spec/models/chat/message_spec.rb +++ b/plugins/chat/spec/models/chat/message_spec.rb @@ -20,16 +20,25 @@ describe Chat::Message do expect(cooked).to eq("

<h1>test</h1>

") end + it "correctly extracts mentions with dots" do + user = Fabricate(:user) + cooked = described_class.cook("@#{user.username}...test") + + expect(cooked).to eq( + "

@#{user.username}…test

", + ) + end + it "does not support headings" do cooked = described_class.cook("## heading 2") expect(cooked).to eq("

## heading 2

") end - it "does not support horizontal rules" do + it "supports horizontal replacement" do cooked = described_class.cook("---") - expect(cooked).to eq("

---

") + expect(cooked).to eq("

") end it "supports backticks rule" do @@ -95,7 +104,7 @@ describe Chat::Message do
#{topic.title}
-

Mark me...this will go down in history.

+

Mark me…this will go down in history.

COOKED