diff --git a/app/services/inline_uploads.rb b/app/services/inline_uploads.rb index d8ddc4eaf0c..35e1f0b4fdf 100644 --- a/app/services/inline_uploads.rb +++ b/app/services/inline_uploads.rb @@ -182,7 +182,7 @@ class InlineUploads end def self.match_bbcode_img(markdown, external_src: false) - markdown.scan(/(\[img\]\s*([^\[\]\s]+)\s*\[\/img\])/) do |match| + markdown.scan(/(\[img\]\s*([^\[\]\s]+)\s*\[\/img\])/i) do |match| if (matched_uploads(match[1]).present? && block_given?) || external_src yield(match[0], match[1], +"![](#{PLACEHOLDER})", $~.offset(0)[0]) end @@ -203,7 +203,7 @@ class InlineUploads end def self.match_anchor(markdown, external_href: false) - markdown.scan(/(()([^<\a>]*?)<\/a>)/) do |match| + markdown.scan(/(()([^<\a>]*?)<\/a>)/i) do |match| node = Nokogiri::HTML::fragment(match[0]).children[0] href = node.attributes["href"]&.value @@ -219,7 +219,7 @@ class InlineUploads end def self.match_img(markdown, external_src: false) - markdown.scan(/(([ ]*)<(?!img)[^<>]+\/?>)?([\r\n]*)(([ ]*)\n]+)>([ ]*))([\r\n]*)/) do |match| + markdown.scan(/(([ ]*)<(?!img)[^<>]+\/?>)?([\r\n]*)(([ ]*)\n]+)>([ ]*))([\r\n]*)/i) do |match| node = Nokogiri::HTML::fragment(match[3].strip).children[0] src = node.attributes["src"]&.value diff --git a/spec/services/inline_uploads_spec.rb b/spec/services/inline_uploads_spec.rb index b42f7c75f78..0bd1e6cb581 100644 --- a/spec/services/inline_uploads_spec.rb +++ b/spec/services/inline_uploads_spec.rb @@ -206,6 +206,20 @@ RSpec.describe InlineUploads do MD end + it "should correct html and markdown uppercase references" do + md = <<~MD + [IMG]#{upload.url}[/IMG] + + Text + MD + + expect(InlineUploads.process(md)).to eq(<<~MD) + ![](#{upload.short_url}) + ![](#{upload2.short_url}) + [Text|attachment](#{upload3.short_url}) + MD + end + context "subfolder" do before do global_setting :relative_url_root, "/community"