FIX: Respect protocol relative URLs in email styling

This commit is contained in:
Robin Ward 2013-08-14 11:32:17 -04:00
parent 7cfb583016
commit b7c50ecdaa
2 changed files with 6 additions and 1 deletions

View File

@ -20,7 +20,7 @@ module Email
img['style'] = "max-width: 694px;"
end
if img['src'][0] == "/"
if img['src'] =~ /^\/[^\/]/
img['src'] = "#{Discourse.base_url}#{img['src']}"
end
end

View File

@ -40,6 +40,11 @@ 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
frag = basic_fragment("<img src='//www.discourse.com/some-image.gif'>")
expect(frag.at("img")["src"]).to eq("//www.discourse.com/some-image.gif")
end
it "strips classes and ids" do
frag = basic_fragment("<div class='foo' id='bar'><div class='foo' id='bar'></div></div>")
expect(frag.to_html).to eq("<div><div></div></div>")