FIX: attachment links in mail lacks protocol

This commit is contained in:
Arpit Jalan
2014-10-27 23:51:55 +05:30
parent 9445000b58
commit 370f50250b
2 changed files with 26 additions and 1 deletions

View File

@ -27,6 +27,7 @@ module Email
def format_basic
uri = URI(Discourse.base_url)
# images
@fragment.css('img').each do |img|
next if img['class'] == 'site-logo'
@ -51,6 +52,20 @@ module Email
img['src'] = "#{uri.scheme}:#{img['src']}"
end
end
# attachments
@fragment.css('a.attachment').each do |a|
# ensure all urls are absolute
if a['href'] =~ /^\/[^\/]/
a['href'] = "#{Discourse.base_url}#{a['href']}"
end
# ensure no schemaless urls
if a['href'] && a['href'].starts_with?("//")
a['href'] = "#{uri.scheme}:#{a['href']}"
end
end
end
def format_notification