FIX: `InlineUploads` does not correct urls with uppercase extension.

FIX: InlineUploads does not correct urls with uppercase extension.

diff --git a/app/services/inline_uploads.rb b/app/services/inline_uploads.rb
index cb153e5..95cabeb 100644
--- a/app/services/inline_uploads.rb
+++ b/app/services/inline_uploads.rb
@@ -6,7 +6,7 @@ class InlineUploads
   PLACEHOLDER = "__replace__"
   PATH_PLACEHOLDER = "__replace_path__"
 
-  UPLOAD_REGEXP_PATTERN = "/original/(\\dX/(?:[a-f0-9]/)*[a-f0-9]{40}[a-z0-9.]*)"
+  UPLOAD_REGEXP_PATTERN = "/original/(\\dX/(?:[a-f0-9]/)*[a-f0-9]{40}[a-zA-Z0-9.]*)"
   private_constant :UPLOAD_REGEXP_PATTERN
 
   def self.process(markdown, on_missing: nil)
@@ -232,9 +232,9 @@ class InlineUploads
     matches = []
 
     regexps = [
-      /(upload:\/\/([a-zA-Z0-9]+)[a-z0-9\.]*)/,
-      /(\/uploads\/short-url\/([a-zA-Z0-9]+)[a-z0-9\.]*)/,
-      /(#{Discourse.base_url}\/uploads\/short-url\/([a-zA-Z0-9]+)[a-z0-9\.]*)/,
+      /(upload:\/\/([a-zA-Z0-9]+)[a-zA-Z0-9\.]*)/,
+      /(\/uploads\/short-url\/([a-zA-Z0-9]+)[a-zA-Z0-9\.]*)/,
+      /(#{Discourse.base_url}\/uploads\/short-url\/([a-zA-Z0-9]+)[a-zA-Z0-9\.]*)/,
     ]
 
     db = RailsMultisite::ConnectionManagement.current_db
diff --git a/spec/services/inline_uploads_spec.rb b/spec/services/inline_uploads_spec.rb
index 5bc4caf..2924293 100644
--- a/spec/services/inline_uploads_spec.rb
+++ b/spec/services/inline_uploads_spec.rb
@@ -211,6 +211,16 @@ RSpec.describe InlineUploads do
         MD
       end
 
+      it "should correct img tags with uppercase upload extension" do
+        md = <<~MD
+        test<img src="#{upload.url.sub(".png", ".PNG")}">
+        MD
+
+        expect(InlineUploads.process(md)).to eq(<<~MD)
+        test![](#{upload.short_url})
+        MD
+      end
+
       it "should correct image URLs to the short version" do
         md = <<~MD
         ![image|690x290](#{upload.short_url})
@@ -503,12 +513,14 @@ RSpec.describe InlineUploads do
         md = <<~MD
         #{upload.url}
         <img src="#{upload.url}" alt="some image">
+        test<img src="#{upload2.url}" alt="some image">test
         <img src="#{URI.join(SiteSetting.s3_cdn_url, URI.parse(upload2.url).path).to_s}" alt="some image">
         MD
 
         expect(InlineUploads.process(md)).to eq(<<~MD)
         ![](#{upload.short_url})
         ![some image](#{upload.short_url})
+        test![some image](#{upload2.short_url})test
         ![some image](#{upload2.short_url})
         MD
       end

GitHub sha: 93c552af

1 Like