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: e476f78bc3/lib/parser_core.js
This commit is contained in:
Joffrey JAFFEUX 2023-10-09 08:30:18 +02:00 committed by GitHub
parent 79ececd976
commit dfe840f71d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 3 deletions

View File

@ -211,6 +211,7 @@ module Chat
strikethrough
blockquote
emphasis
replacements
]
def self.cook(message, opts = {})

View File

@ -20,16 +20,25 @@ describe Chat::Message do
expect(cooked).to eq("<p>&lt;h1&gt;test&lt;/h1&gt;</p>")
end
it "correctly extracts mentions with dots" do
user = Fabricate(:user)
cooked = described_class.cook("@#{user.username}...test")
expect(cooked).to eq(
"<p><a class=\"mention\" href=\"/u/#{user.username}\">@#{user.username}</a>…test</p>",
)
end
it "does not support headings" do
cooked = described_class.cook("## heading 2")
expect(cooked).to eq("<p>## heading 2</p>")
end
it "does not support horizontal rules" do
it "supports horizontal replacement" do
cooked = described_class.cook("---")
expect(cooked).to eq("<p>---</p>")
expect(cooked).to eq("<p></p>")
end
it "supports backticks rule" do
@ -95,7 +104,7 @@ describe Chat::Message do
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="#{avatar_src}" class="avatar"><a href="http://test.localhost/t/some-quotable-topic/#{topic.id}/#{post.post_number}">#{topic.title}</a></div>
<blockquote>
<p>Mark me...this will go down in history.</p>
<p>Mark methis will go down in history.</p>
</blockquote>
</aside>
COOKED