FIX: Skip upload if HTML cannot be parsed (#12971)

FIX: Skip upload if HTML cannot be parsed (#12971)

diff --git a/app/services/inline_uploads.rb b/app/services/inline_uploads.rb
index a63f0af..59d3c77 100644
--- a/app/services/inline_uploads.rb
+++ b/app/services/inline_uploads.rb
@@ -200,7 +200,7 @@ class InlineUploads
   def self.match_img(markdown, external_src: false, uploads: nil)
     markdown.scan(/(<(?!img)[^<>]+\/?>)?(\s*)(<img [^>\n]+>)/i) do |match|
       node = Nokogiri::HTML5::fragment(match[2].strip).children[0]
-      src =  node.attributes["src"]&.value
+      src = node&.attributes&.[]("src")&.value
 
       if src && (matched_uploads(src).present? || external_src)
         upload = uploads&.[](src)
diff --git a/spec/services/inline_uploads_spec.rb b/spec/services/inline_uploads_spec.rb
index c6e4835..c46b6d7 100644
--- a/spec/services/inline_uploads_spec.rb
+++ b/spec/services/inline_uploads_spec.rb
@@ -54,6 +54,11 @@ RSpec.describe InlineUploads do
         MD
       end
 
+      it "should work with invalid img tags" do
+        md = '<img data-id="<>">'
+        expect(InlineUploads.process(md)).to eq(md)
+      end
+
       it "should not correct code blocks" do
         md = "`<a class=\"attachment\" href=\"#{upload2.url}\">In Code Block</a>`"
 

GitHub sha: c0679022

This commit appears in #12971 which was approved by eviltrout. It was merged by nbianca.