mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 08:09:33 +08:00
FIX: attachment links in mail lacks protocol
This commit is contained in:
parent
9445000b58
commit
370f50250b
|
@ -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
|
||||
|
|
|
@ -113,6 +113,11 @@ describe Email::Styles do
|
|||
frag.at('a')['href'].should == "http://test.localhost/discourse"
|
||||
end
|
||||
|
||||
it "rewrites the href for attachment files to have http" do
|
||||
frag = html_fragment('<a class="attachment" href="//try-discourse.global.ssl.fastly.net/uploads/default/368/40b610b0aa90cfcf.txt">attachment_file.txt</a>')
|
||||
frag.at('a')['href'].should == "http://try-discourse.global.ssl.fastly.net/uploads/default/368/40b610b0aa90cfcf.txt"
|
||||
end
|
||||
|
||||
it "rewrites the src to have http" do
|
||||
frag = html_fragment('<img src="//test.localhost/blah.jpg">')
|
||||
frag.at('img')['src'].should == "http://test.localhost/blah.jpg"
|
||||
|
@ -124,11 +129,16 @@ describe Email::Styles do
|
|||
SiteSetting.stubs(:use_https).returns(true)
|
||||
end
|
||||
|
||||
it "rewrites the forum URL to have http" do
|
||||
it "rewrites the forum URL to have https" do
|
||||
frag = html_fragment('<a href="//test.localhost/discourse">hello</a>')
|
||||
frag.at('a')['href'].should == "https://test.localhost/discourse"
|
||||
end
|
||||
|
||||
it "rewrites the href for attachment files to have https" do
|
||||
frag = html_fragment('<a class="attachment" href="//try-discourse.global.ssl.fastly.net/uploads/default/368/40b610b0aa90cfcf.txt">attachment_file.txt</a>')
|
||||
frag.at('a')['href'].should == "https://try-discourse.global.ssl.fastly.net/uploads/default/368/40b610b0aa90cfcf.txt"
|
||||
end
|
||||
|
||||
it "rewrites the src to have https" do
|
||||
frag = html_fragment('<img src="//test.localhost/blah.jpg">')
|
||||
frag.at('img')['src'].should == "https://test.localhost/blah.jpg"
|
||||
|
|
Loading…
Reference in New Issue
Block a user