From cac7438fffb9d5a8f9e4bed05f022d5698710cdf Mon Sep 17 00:00:00 2001 From: Sivin Varghese <64252451+iamsivin@users.noreply.github.com> Date: Fri, 27 Mar 2026 10:14:57 +0530 Subject: [PATCH] fix: Email Channel links are not working (backend) (#13898) # Pull Request Template ## Description This PR fixes the link formatting issue on the backend by adding `:autolink` to `ChatwootMarkdownRenderer#render_message`, ensuring all URLs are converted to `` tags. Fixes https://linear.app/chatwoot/issue/CW-6682/email-channel-links-are-not-working ## Type of change - [x] Bug fix (non-breaking change which fixes an issue) ## Checklist: - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my code - [ ] I have commented on my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [x] New and existing unit tests pass locally with my changes - [ ] Any dependent changes have been merged and published in downstream modules --------- Co-authored-by: Sojan Jose --- lib/chatwoot_markdown_renderer.rb | 2 +- spec/lib/chatwoot_markdown_renderer_spec.rb | 18 +++++++++++------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/lib/chatwoot_markdown_renderer.rb b/lib/chatwoot_markdown_renderer.rb index 50d1755ee..c7adac30a 100644 --- a/lib/chatwoot_markdown_renderer.rb +++ b/lib/chatwoot_markdown_renderer.rb @@ -5,7 +5,7 @@ class ChatwootMarkdownRenderer def render_message markdown_renderer = BaseMarkdownRenderer.new - doc = CommonMarker.render_doc(@content, :DEFAULT, [:strikethrough]) + doc = CommonMarker.render_doc(@content, :DEFAULT, [:strikethrough, :autolink]) html = markdown_renderer.render(doc) render_as_html_safe(html) end diff --git a/spec/lib/chatwoot_markdown_renderer_spec.rb b/spec/lib/chatwoot_markdown_renderer_spec.rb index 5b66ed869..da2a50316 100644 --- a/spec/lib/chatwoot_markdown_renderer_spec.rb +++ b/spec/lib/chatwoot_markdown_renderer_spec.rb @@ -6,11 +6,9 @@ RSpec.describe ChatwootMarkdownRenderer do let(:doc) { instance_double(CommonMarker::Node) } let(:renderer) { described_class.new(markdown_content) } let(:markdown_renderer) { instance_double(CustomMarkdownRenderer) } - let(:base_markdown_renderer) { instance_double(BaseMarkdownRenderer) } let(:html_content) { '

This is a test content with markdown

' } before do - allow(CommonMarker).to receive(:render_doc).with(markdown_content, :DEFAULT, [:strikethrough]).and_return(doc) allow(CustomMarkdownRenderer).to receive(:new).and_return(markdown_renderer) allow(markdown_renderer).to receive(:render).with(doc).and_return(html_content) end @@ -64,22 +62,28 @@ RSpec.describe ChatwootMarkdownRenderer do end describe '#render_message' do - let(:message_html_content) { '

This is a test content with ^markdown^

' } let(:rendered_message) { renderer.render_message } before do - allow(CommonMarker).to receive(:render_html).with(markdown_content).and_return(message_html_content) - allow(BaseMarkdownRenderer).to receive(:new).and_return(base_markdown_renderer) - allow(base_markdown_renderer).to receive(:render).with(doc).and_return(message_html_content) + allow(CommonMarker).to receive(:render_doc).and_call_original + allow(BaseMarkdownRenderer).to receive(:new).and_call_original end it 'renders the markdown message to html' do - expect(rendered_message.to_s).to eq(message_html_content) + expect(rendered_message.to_s).to eq("

This is a test content with ^markdown^

\n") end it 'returns an html safe string' do expect(rendered_message).to be_html_safe end + + context 'with bare URLs' do + let(:markdown_content) { 'Visit https://example.com for details' } + + it 'converts bare URLs to links' do + expect(renderer.render_message.to_s).to eq("

Visit https://example.com for details

\n") + end + end end describe '#render_markdown_to_plain_text' do