FIX: Incorrect CDN URL for site setting uploads when s3 is enabled.

FIX: Incorrect CDN URL for site setting uploads when s3 is enabled.

diff --git a/lib/global_path.rb b/lib/global_path.rb
index 10d1fbd..17479b6 100644
--- a/lib/global_path.rb
+++ b/lib/global_path.rb
@@ -11,7 +11,8 @@ module GlobalPath
     if SiteSetting.Upload.s3_cdn_url.present?
       p = Discourse.store.cdn_url(p)
     end
-    p =~ /^http/ ? p : cdn_path(p)
+
+    (p =~ /^http/ || p =~ /^\/\//) ? p : cdn_path(p)
   end
 
   def cdn_relative_path(path)
diff --git a/spec/helpers/user_notifications_helper_spec.rb b/spec/helpers/user_notifications_helper_spec.rb
index 735a69e..f1aeb8a 100644
--- a/spec/helpers/user_notifications_helper_spec.rb
+++ b/spec/helpers/user_notifications_helper_spec.rb
@@ -108,6 +108,16 @@ describe UserNotificationsHelper do
         )
       end
 
+      describe 'when global cdn path is configured' do
+        it 'should return the right url' do
+          GlobalSetting.stubs(:cdn_url).returns('https://some.cdn.com/cluster')
+
+          expect(helper.logo_url).to eq(
+            "http://s3-upload-bucket.s3.dualstack.us-east-1.amazonaws.com/original/1X/somesha1.png"
+          )
+        end
+      end
+
       describe 'when cdn path is configured' do
         before do
           SiteSetting.s3_cdn_url = 'https://some.cdn.com'

GitHub sha: 5f0f7f90

1 Like

We also have global_setting :cdn_url, "https://some.cdn.com/cluster", A tiny bit more concise and takes care of a cache flush we need for s3.

1 Like