diff --git a/app/services/inline_uploads.rb b/app/services/inline_uploads.rb
index a63f0af9c05..59d3c7738af 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*)(\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 c6e4835b65c..c46b6d7b69a 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 = ''
+ expect(InlineUploads.process(md)).to eq(md)
+ end
+
it "should not correct code blocks" do
md = "`In Code Block`"