FIX: Handle `mailto` links in slack messages

This commit is contained in:
David Taylor 2019-01-03 11:14:26 +00:00
parent bf1939f08d
commit b7dff35722
2 changed files with 14 additions and 0 deletions

View File

@ -41,6 +41,8 @@ module DiscourseChat::Provider::SlackProvider
uri = URI(url) rescue nil uri = URI(url) rescue nil
return Discourse.current_hostname unless uri return Discourse.current_hostname unless uri
return uri.to_s if uri.scheme == "mailto"
uri.host = Discourse.current_hostname if !uri.host uri.host = Discourse.current_hostname if !uri.host
uri.scheme = (SiteSetting.force_https ? 'https' : 'http') if !uri.scheme uri.scheme = (SiteSetting.force_https ? 'https' : 'http') if !uri.scheme
uri.to_s uri.to_s

View File

@ -49,6 +49,18 @@ RSpec.describe DiscourseChat::Provider::SlackProvider do
.to eq('<http://somesource.com|meta.discourse.org>') .to eq('<http://somesource.com|meta.discourse.org>')
end end
end end
describe 'when post contains an email' do
it 'should return the right excerpt' do
post.update!(cooked: <<~COOKED
The address is <a href=\"mailto:someone@domain.com\">my email</a>
COOKED
)
expect(described_class.excerpt(post))
.to eq('The address is <mailto:someone@domain.com|my email>')
end
end
end end
describe '.trigger_notifications' do describe '.trigger_notifications' do