mirror of
https://github.com/discourse/discourse.git
synced 2024-11-29 04:03:57 -06:00
FIX: incorrect emoji stripping logic
This commit is contained in:
parent
c2197de11e
commit
27b1ec2917
@ -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
|
||||||
|
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user