diff --git a/lib/email/styles.rb b/lib/email/styles.rb index eb3074f5b87..4b51a023315 100644 --- a/lib/email/styles.rb +++ b/lib/email/styles.rb @@ -191,8 +191,10 @@ module Email def strip_avatars_and_emojis @fragment.search('img').each do |img| + next unless img['src'] + 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 end diff --git a/spec/components/email/styles_spec.rb b/spec/components/email/styles_spec.rb index 38ccdde9629..e8f7b594e97 100644 --- a/spec/components/email/styles_spec.rb +++ b/spec/components/email/styles_spec.rb @@ -173,6 +173,13 @@ describe Email::Styles do style.strip_avatars_and_emojis expect(style.to_html).to match_html("cry_cry") end + + it "works if img tag has no attrs" do + cooked = "Create a method for click on image and use ng-click in in your slide box...it is simple" + style = Email::Styles.new(cooked) + style.strip_avatars_and_emojis + expect(style.to_html).to eq(cooked) + end end context "onebox_styles" do