FIX: incorrect emoji stripping logic

This commit is contained in:
Sam 2015-08-19 09:12:08 +10:00
parent c2197de11e
commit 27b1ec2917
2 changed files with 21 additions and 2 deletions

View File

@ -159,13 +159,16 @@ module Email
end end
def strip_avatars_and_emojis def strip_avatars_and_emojis
@fragment.css('img').each do |img| @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.parent['style'] = "vertical-align: top;" if img.parent.name == 'td'
img.remove img.remove
end end
img.replace(img['title']) if (img['src'] =~ /images\/emoji/ || img['src'] =~ /uploads\/default\/_emoji/) if img['title'] && (img['src'] =~ /images\/emoji/ || img['src'] =~ /uploads\/default\/_emoji/)
img.add_previous_sibling(img['title'] || "emoji")
img.remove
end
end end
@fragment.to_s @fragment.to_s

View File

@ -147,5 +147,21 @@ describe Email::Styles do
end end
context "strip_avatars_and_emojis" do
it "works for lonesome emoji with no title" do
emoji = "<img src='/images/emoji/emoji_one/crying_cat_face.png'>"
style = Email::Styles.new(emoji)
style.strip_avatars_and_emojis
expect(style.to_html).to match_html(emoji)
end
it "works for lonesome emoji with title" do
emoji = "<img title='cry_cry' src='/images/emoji/emoji_one/crying_cat_face.png'>"
style = Email::Styles.new(emoji)
style.strip_avatars_and_emojis
expect(style.to_html).to match_html("cry_cry")
end
end
end end