FIX: 'local_cdn_url' method should work for local relative urls too.

This commit is contained in:
Vinoth Kannan 2019-10-14 11:39:16 +05:30
parent 99086edf85
commit f92a6f7ac5
2 changed files with 16 additions and 1 deletions

View File

@ -71,7 +71,11 @@ class UrlHelper
def self.local_cdn_url(url)
return url if Discourse.asset_host.blank?
url.sub(Discourse.base_url_no_prefix, Discourse.asset_host)
if url.start_with?("/#{Discourse.store.upload_path}/")
"#{Discourse.asset_host}#{url}"
else
url.sub(Discourse.base_url_no_prefix, Discourse.asset_host)
end
end
end

View File

@ -119,4 +119,15 @@ describe UrlHelper do
end
end
describe "#local_cdn_url" do
let(:url) { "/uploads/default/1X/575bcc2886bf7a39684b57ca90be85f7d399bbc7.png" }
let(:asset_host) { "//my.awesome.cdn" }
it "should return correct cdn url for local relative urls" do
Discourse.stubs(:asset_host).returns(asset_host)
cdn_url = UrlHelper.local_cdn_url(url)
expect(cdn_url).to eq("#{asset_host}#{url}")
end
end
end