A platform for community discussion. Free, open, simple.
replace subfolder on cdn url conversion between general cdn and s3 (#7764)
Jeff Wong893b50031d65
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rbindex cb1e0a1d2b2..dfb1d5e88a8 100644--- a/app/helpers/application_helper.rb+++ b/app/helpers/application_helper.rb@@ -1,3 +1,4 @@+# coding: utf-8# frozen_string_literal: truerequire 'current_user'require 'canonical_url'@@ -62,7 +63,8 @@ module ApplicationHelperif GlobalSetting.use_s3? && GlobalSetting.s3_cdn_urlif GlobalSetting.cdn_url- path = path.gsub(GlobalSetting.cdn_url, GlobalSetting.s3_cdn_url)+ folder = ActionController::Base.config.relative_url_root || "/"+ path = path.gsub(File.join(GlobalSetting.cdn_url, folder, "/"), File.join(GlobalSetting.s3_cdn_url, "/"))else# we must remove the subfolder path here, assets are uploaded to s3# without it getting involveddiff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rbindex d55023f3e1b..25e75430da9 100644--- a/spec/helpers/application_helper_spec.rb+++ b/spec/helpers/application_helper_spec.rb@@ -1,3 +1,4 @@+# coding: utf-8# frozen_string_literal: truerequire 'rails_helper'@@ -32,6 +33,13 @@ describe ApplicationHelper doexpect(helper.preload_script("application")).to include('https://s3cdn.com/assets/application.js')end+ it "replaces cdn URLs with s3 cdn subfolder paths" do+ global_setting :s3_cdn_url, 'https://s3cdn.com/s3_subpath'+ set_cdn_url "https://awesome.com"+ ActionController::Base.config.relative_url_root = "/community"+ expect(helper.preload_script("application")).to include('https://s3cdn.com/s3_subpath/assets/application.js')+ end+it "returns magic brotli mangling for brotli requests" dohelper.request.env["HTTP_ACCEPT_ENCODING"] = 'br'