2
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2025-09-05 08:59:27 +08:00

FIX: schemaless urls in emails

This commit is contained in:
Régis Hanol 2013-08-27 00:08:38 +02:00
parent 7c07079ed9
commit 561792a615
2 changed files with 8 additions and 5 deletions

View file

@ -20,9 +20,15 @@ module Email
img['style'] = "max-width: 694px;" img['style'] = "max-width: 694px;"
end end
# ensure all urls are absolute
if img['src'] =~ /^\/[^\/]/ if img['src'] =~ /^\/[^\/]/
img['src'] = "#{Discourse.base_url}#{img['src']}" img['src'] = "#{Discourse.base_url}#{img['src']}"
end end
# ensure no schemaless urls
if img['src'].starts_with?("//")
img['src'] = "http:" + img['src']
end
end end
end end
@ -42,9 +48,7 @@ module Email
reset_tables reset_tables
end end
def format_html def format_html
style('h3', 'margin: 15px 0 20px 0; border-bottom: 1px solid #ddd;') style('h3', 'margin: 15px 0 20px 0; border-bottom: 1px solid #ddd;')
style('hr', 'background-color: #ddd; height: 1px; border: 1px;') style('hr', 'background-color: #ddd; height: 1px; border: 1px;')
style('a',' text-decoration: none; font-weight: bold; color: #006699;') style('a',' text-decoration: none; font-weight: bold; color: #006699;')
@ -58,7 +62,6 @@ module Email
pre.replace(pre.text) pre.replace(pre.text)
end end
end end
def to_html def to_html

View file

@ -40,9 +40,9 @@ describe Email::Styles do
expect(frag.at("img")["src"]).to eq("#{Discourse.base_url}/some-image.png") expect(frag.at("img")["src"]).to eq("#{Discourse.base_url}/some-image.png")
end end
it "it does not change protocol relative paths" do it "prefixes schemaless image urls with http:" do
frag = basic_fragment("<img src='//www.discourse.com/some-image.gif'>") frag = basic_fragment("<img src='//www.discourse.com/some-image.gif'>")
expect(frag.at("img")["src"]).to eq("//www.discourse.com/some-image.gif") expect(frag.at("img")["src"]).to eq("http://www.discourse.com/some-image.gif")
end end
it "strips classes and ids" do it "strips classes and ids" do