A platform for community discussion. Free, open, simple.
DEV: skip S3 CDN urls with different path in prefix. (#14488)
Vinoth Kannanc8d5c049eb0c
diff --git a/lib/file_store/s3_store.rb b/lib/file_store/s3_store.rbindex 1c9f7e56abc..2e636818215 100644--- a/lib/file_store/s3_store.rb+++ b/lib/file_store/s3_store.rb@@ -158,8 +158,11 @@ module FileStoreendreturn false if SiteSetting.Upload.s3_cdn_url.blank?- cdn_hostname = URI.parse(SiteSetting.Upload.s3_cdn_url || "").hostname- return true if cdn_hostname.presence && url[cdn_hostname]++ s3_cdn_url = URI.parse(SiteSetting.Upload.s3_cdn_url || "")+ cdn_hostname = s3_cdn_url.hostname++ return true if cdn_hostname.presence && url[cdn_hostname] && (s3_cdn_url.path.blank? || parsed_url.path.starts_with?(s3_cdn_url.path))falseenddiff --git a/spec/models/post_spec.rb b/spec/models/post_spec.rbindex 5c5eb12a2d5..879eca29e1a 100644--- a/spec/models/post_spec.rb+++ b/spec/models/post_spec.rb@@ -1715,6 +1715,17 @@ describe Post dopost.each_upload_url { |src, _, _| urls << src }expect(urls).to be_emptyend++ it "skip S3 cdn urls with different path" do+ setup_s3+ SiteSetting.Upload.stubs(:s3_cdn_url).returns("https://cdn.example.com/site1")++ urls = []+ raw = "<img src='https://cdn.example.com/site1/original/1X/bc68acbc8c022726e69f980e00d6811212r.jpg' /><img src='https://cdn.example.com/site2/original/1X/bc68acbc8c022726e69f980e00d68112128.jpg' />"+ post = Fabricate(:post, raw: raw)+ post.each_upload_url { |src, _, _| urls << src }+ expect(urls).to contain_exactly("https://cdn.example.com/site1/original/1X/bc68acbc8c022726e69f980e00d6811212r.jpg")+ endenddescribe "#publish_changes_to_client!" do