diff --git a/app/services/inline_uploads.rb b/app/services/inline_uploads.rb index bf42ac94e87..31a3319a48d 100644 --- a/app/services/inline_uploads.rb +++ b/app/services/inline_uploads.rb @@ -214,7 +214,7 @@ class InlineUploads end def self.match_img(markdown, external_src: false) - markdown.scan(/(([ ]*)<(?!img)[^<>]+\/?>)?(\n*)(([ ]*)\n]+)>([ ]*))(\n*)/) do |match| + markdown.scan(/(([ ]*)<(?!img)[^<>]+\/?>)?([\r\n]*)(([ ]*)\n]+)>([ ]*))([\r\n]*)/) do |match| node = Nokogiri::HTML::fragment(match[3].strip).children[0] src = node.attributes["src"]&.value @@ -245,8 +245,12 @@ class InlineUploads match[3].strip! if !after_html_tag - if match[1].nil? || match[1].length < 4 - yield(match[3], src, replacement, $~.offset(0)[0]) if block_given? + if (match[1].nil? || match[1].length < 4) + if (match[4].nil? || match[4].length < 4) + yield(match[3], src, replacement, $~.offset(0)[0]) if block_given? + else + yield(match[3], src, match[3].sub(src, PATH_PLACEHOLDER), $~.offset(0)[0]) if block_given? + end else yield(match[3], src, match[3].sub(src, PATH_PLACEHOLDER), $~.offset(0)[0]) if block_given? end diff --git a/spec/services/inline_uploads_spec.rb b/spec/services/inline_uploads_spec.rb index 82ad449a9e7..434bf429b42 100644 --- a/spec/services/inline_uploads_spec.rb +++ b/spec/services/inline_uploads_spec.rb @@ -325,6 +325,10 @@ RSpec.describe InlineUploads do MD + + md = "
\r\n\r\n \r\n" + + expect(InlineUploads.process(md)).to eq("\r\n\r\n \r\n") end it "should correctly update image sources within anchor or paragraph tags" do