FIX: make markdown regexp patterns case insensitive.

FIX: make markdown regexp patterns case insensitive.

diff --git a/app/services/inline_uploads.rb b/app/services/inline_uploads.rb
index d8ddc4e..35e1f0b 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>]*?)<\/a>)/) do |match|
+    markdown.scan(/((<a[^<]+>)([^<\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]*)(([ ]*)<img ([^>\n]+)>([ ]*))([\r\n]*)/) do |match|
+    markdown.scan(/(([ ]*)<(?!img)[^<>]+\/?>)?([\r\n]*)(([ ]*)<img ([^>\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 b42f7c7..0bd1e6c 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]
+        <IMG src="#{upload2.url}" />
+        <A class="attachment" href="#{upload3.url}">Text</A>
+        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"

GitHub sha: 321f559c

1 Like