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