From b8cf0788c69e45b29f23cebdd6a5e8cd6fe7bc95 Mon Sep 17 00:00:00 2001 From: Neil Lalonde Date: Fri, 8 Jun 2018 13:11:52 -0400 Subject: [PATCH] FIX: broken mailto href's in emails --- lib/pretty_text.rb | 4 +++- spec/components/pretty_text_spec.rb | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/pretty_text.rb b/lib/pretty_text.rb index 83001ce8370..23bd9fb7b78 100644 --- a/lib/pretty_text.rb +++ b/lib/pretty_text.rb @@ -360,7 +360,9 @@ module PrettyText begin uri = URI(href) site_uri ||= URI(Discourse.base_url) - link["href"] = "#{site_uri}#{link['href']}" unless uri.host.present? + unless uri.host.present? || href.start_with?('mailto') + link["href"] = "#{site_uri}#{link['href']}" + end rescue URI::InvalidURIError, URI::InvalidComponentError # leave it end diff --git a/spec/components/pretty_text_spec.rb b/spec/components/pretty_text_spec.rb index 62a02b74fc4..60d5dc3cc53 100644 --- a/spec/components/pretty_text_spec.rb +++ b/spec/components/pretty_text_spec.rb @@ -628,6 +628,11 @@ describe PrettyText do html = "

Check out this guy.

" expect { described_class.format_for_email(html, post) }.to_not raise_error end + + it "doesn't change mailto" do + html = "

Contact me at this address.

" + expect(PrettyText.format_for_email(html, post)).to eq(html) + end end it 'Is smart about linebreaks and IMG tags' do