A platform for community discussion. Free, open, simple.
FIX: broken mailto href's in emails
Neil Lalondeb8cf0788c69e
diff --git a/lib/pretty_text.rb b/lib/pretty_text.rbindex 83001ce8370..23bd9fb7b78 100644--- a/lib/pretty_text.rb+++ b/lib/pretty_text.rb@@ -360,7 +360,9 @@ module PrettyTextbeginuri = 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']}"+ endrescue URI::InvalidURIError, URI::InvalidComponentError# leave itenddiff --git a/spec/components/pretty_text_spec.rb b/spec/components/pretty_text_spec.rbindex 62a02b74fc4..60d5dc3cc53 100644--- a/spec/components/pretty_text_spec.rb+++ b/spec/components/pretty_text_spec.rb@@ -628,6 +628,11 @@ describe PrettyText dohtml = "<p>Check out <a href=\"not a real url\">this guy</a>.</p>"expect { described_class.format_for_email(html, post) }.to_not raise_errorend++ it "doesn't change mailto" do+ html = "<p>Contact me at <a href=\"mailto:[email protected]\">this address</a>.</p>"+ expect(PrettyText.format_for_email(html, post)).to eq(html)+ endendit 'Is smart about linebreaks and IMG tags' do