diff --git a/lib/cooked_post_processor.rb b/lib/cooked_post_processor.rb index 7abe28bd65d..e722ed842f7 100644 --- a/lib/cooked_post_processor.rb +++ b/lib/cooked_post_processor.rb @@ -308,8 +308,8 @@ class CookedPostProcessor end def optimize_urls - # when login is required, attachments can't be on the CDN - if SiteSetting.login_required + # attachments can't be on the CDN when either setting is enabled + if SiteSetting.login_required || SiteSetting.prevent_anons_from_downloading_files @doc.css("a.attachment[href]").each do |a| href = a["href"].to_s a["href"] = UrlHelper.schemaless UrlHelper.absolute_without_cdn(href) if UrlHelper.is_local(href) diff --git a/spec/components/cooked_post_processor_spec.rb b/spec/components/cooked_post_processor_spec.rb index ba3a701b264..6709417be29 100644 --- a/spec/components/cooked_post_processor_spec.rb +++ b/spec/components/cooked_post_processor_spec.rb @@ -446,28 +446,65 @@ describe CookedPostProcessor do it "uses schemaless url for uploads" do cpp.optimize_urls - expect(cpp.html).to match_html '
' + expect(cpp.html).to match_html 'Link
+
+ Google
+
+ text.txt (20 Bytes)
+
+
Link
+
+ Google
+
+ text.txt (20 Bytes)
+
+
Link
+
+ Google
+
+ text.txt (20 Bytes)
+
+