From 1a435414d5493ac829b41da283537d4b7115055f Mon Sep 17 00:00:00 2001 From: Gerhard Schlager Date: Fri, 22 Sep 2017 14:26:06 +0200 Subject: [PATCH] FIX: handle URL encoded email addresses --- app/models/topic_embed.rb | 2 +- spec/models/topic_embed_spec.rb | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/app/models/topic_embed.rb b/app/models/topic_embed.rb index ece08ced70b..8803a29b053 100644 --- a/app/models/topic_embed.rb +++ b/app/models/topic_embed.rb @@ -125,7 +125,7 @@ class TopicEmbed < ActiveRecord::Base uri.host = original_uri.host node[url_param] = uri.to_s end - rescue URI::InvalidURIError + rescue URI::InvalidURIError, URI::InvalidComponentError # If there is a mistyped URL, just do nothing end end diff --git a/spec/models/topic_embed_spec.rb b/spec/models/topic_embed_spec.rb index 8da66b32b6d..44a37959ed0 100644 --- a/spec/models/topic_embed_spec.rb +++ b/spec/models/topic_embed_spec.rb @@ -195,6 +195,23 @@ describe TopicEmbed do end end + context "emails" do + let(:url) { 'http://example.com/foo' } + let(:contents) { '

URL encoded @ symbol

normal mailto link

' } + let!(:embeddable_host) { Fabricate(:embeddable_host) } + let!(:file) { StringIO.new } + + before do + file.stubs(:read).returns contents + TopicEmbed.stubs(:open).returns file + end + + it "handles mailto links" do + response = TopicEmbed.find_remote(url) + expect(response.body).to have_tag('a', with: { href: 'mailto:foo%40example.com' }) + expect(response.body).to have_tag('a', with: { href: 'mailto:bar@example.com' }) + end + end end end