mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 17:06:31 -06:00
FIX: prevent huge custom emojis in emails
This commit is contained in:
parent
d4bbdcd7d6
commit
8fc7420f83
@ -37,25 +37,20 @@ module Email
|
||||
@fragment.css('img').each do |img|
|
||||
next if img['class'] == 'site-logo'
|
||||
|
||||
if img['class'] == "emoji" || img['src'] =~ /(plugins|images)\/emoji/
|
||||
img['width'] = 20
|
||||
img['height'] = 20
|
||||
if (img['class'] && img['class']['emoji']) || (img['src'] && img['src'][/\/_?emoji\//])
|
||||
img['width'] = img['height'] = 20
|
||||
else
|
||||
# use dimensions of original iPhone screen for 'too big, let device rescale'
|
||||
if img['width'].to_i > 320 or img['height'].to_i > 480
|
||||
img['width'] = 'auto'
|
||||
img['height'] = 'auto'
|
||||
img['width'] = img['height'] = 'auto'
|
||||
end
|
||||
end
|
||||
|
||||
# ensure all urls are absolute
|
||||
if img['src'] =~ /^\/[^\/]/
|
||||
img['src'] = "#{Discourse.base_url}#{img['src']}"
|
||||
end
|
||||
|
||||
# ensure no schemaless urls
|
||||
if img['src'] && img['src'].starts_with?("//")
|
||||
img['src'] = "#{uri.scheme}:#{img['src']}"
|
||||
if img['src']
|
||||
# ensure all urls are absolute
|
||||
img['src'] = "#{Discourse.base_url}#{img['src']}" if img['src'][/^\/[^\/]/]
|
||||
# ensure no schemaless urls
|
||||
img['src'] = "#{uri.scheme}:#{img['src']}" if img['src'][/^\/\//]
|
||||
end
|
||||
end
|
||||
|
||||
@ -199,12 +194,12 @@ module Email
|
||||
|
||||
def strip_avatars_and_emojis
|
||||
@fragment.search('img').each do |img|
|
||||
if img['src'] =~ /_avatar/
|
||||
if img['src'][/_avatar/]
|
||||
img.parent['style'] = "vertical-align: top;" if img.parent.name == 'td'
|
||||
img.remove
|
||||
end
|
||||
|
||||
if img['title'] && (img['src'] =~ /images\/emoji/ || img['src'] =~ /uploads\/default\/_emoji/)
|
||||
if img['title'] && img['src'][/\/_?emoji\//]
|
||||
img.add_previous_sibling(img['title'] || "emoji")
|
||||
img.remove
|
||||
end
|
||||
|
@ -30,12 +30,18 @@ describe Email::Styles do
|
||||
expect(frag.at("img")["style"]).to match("max-width")
|
||||
end
|
||||
|
||||
it "adds a width and height to images with an emoji path" do
|
||||
it "adds a width and height to emojis" do
|
||||
frag = basic_fragment("<img src='/images/emoji/fish.png' class='emoji'>")
|
||||
expect(frag.at("img")["width"]).to eq("20")
|
||||
expect(frag.at("img")["height"]).to eq("20")
|
||||
end
|
||||
|
||||
it "adds a width and height to custom emojis" do
|
||||
frag = basic_fragment("<img src='/uploads/default/_emoji/fish.png' class='emoji emoji-custom'>")
|
||||
expect(frag.at("img")["width"]).to eq("20")
|
||||
expect(frag.at("img")["height"]).to eq("20")
|
||||
end
|
||||
|
||||
it "converts relative paths to absolute paths" do
|
||||
frag = basic_fragment("<img src='/some-image.png'>")
|
||||
expect(frag.at("img")["src"]).to eq("#{Discourse.base_url}/some-image.png")
|
||||
|
Loading…
Reference in New Issue
Block a user