FIX: inline_uploads not working on subfolder setups

FIX: inline_uploads not working on subfolder setups

diff --git a/app/services/inline_uploads.rb b/app/services/inline_uploads.rb
index 7a32043..039d5f3 100644
--- a/app/services/inline_uploads.rb
+++ b/app/services/inline_uploads.rb
@@ -278,7 +278,7 @@ class InlineUploads
       /(upload:\/\/([a-zA-Z0-9]+)[a-zA-Z0-9\.]*)/,
       /(\/uploads\/short-url\/([a-zA-Z0-9]+)[a-zA-Z0-9\.]*)/,
       /(#{base_url}\/uploads\/short-url\/([a-zA-Z0-9]+)[a-zA-Z0-9\.]*)/,
-      /(\/uploads\/#{db}#{UPLOAD_REGEXP_PATTERN})/,
+      /(#{GlobalSetting.relative_url_root}\/uploads\/#{db}#{UPLOAD_REGEXP_PATTERN})/,
       /(#{base_url}\/uploads\/#{db}#{UPLOAD_REGEXP_PATTERN})/,
     ]
 
diff --git a/spec/services/inline_uploads_spec.rb b/spec/services/inline_uploads_spec.rb
index 9a39d93..41646c3 100644
--- a/spec/services/inline_uploads_spec.rb
+++ b/spec/services/inline_uploads_spec.rb
@@ -206,6 +206,28 @@ RSpec.describe InlineUploads do
         MD
       end
 
+      context "subfolder" do
+        before do
+          global_setting :relative_url_root, "/community"
+          ActionController::Base.config.relative_url_root = "/community"
+        end
+
+        after do
+          ActionController::Base.config.relative_url_root = nil
+        end
+
+        it "should correct subfolder images" do
+
+          md = <<~MD
+            <img src="/community#{upload.url}">
+          MD
+
+          expect(InlineUploads.process(md)).to eq(<<~MD)
+            ![](#{upload.short_url})
+          MD
+        end
+      end
+
       it "should correct raw image URLs to the short url and paths" do
         md = <<~MD
         #{Discourse.base_url}#{upload.url}

GitHub sha: cd894b7d

2 Likes

This commit has been mentioned on Discourse Meta. There might be relevant details there: