mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-28 01:56:01 -05:00
Merge pull request #2922 from techAPJ/patch-2
FIX: attachment links in mail lacks protocol
This commit is contained in:
commit
0965baad72
2 changed files with 26 additions and 1 deletions
|
@ -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 a new issue