From eb9f306e64d5e7e7e75217737fdf8b757de840d0 Mon Sep 17 00:00:00 2001
From: Neil Lalonde <neillalonde@gmail.com>
Date: Thu, 15 Jun 2017 10:36:11 -0400
Subject: [PATCH] FIX: fail to send email notification if post has img tag with
 no src attribute

---
 lib/email/styles.rb                  | 4 +++-
 spec/components/email/styles_spec.rb | 7 +++++++
 2 files changed, 10 insertions(+), 1 deletion(-)

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 <img> 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