From 7a5a195dc0357d09967791497c06ce082c805b60 Mon Sep 17 00:00:00 2001 From: Sam Date: Fri, 24 Jul 2015 14:08:32 +1000 Subject: [PATCH] FIX: properly support HTTPS CDN on HTTP site Previously we changed all CDN links to schemaless. This is desirable for non HTTPS sites, to ease migration to HTTPS. It is not desirable for secure sites. Once site is secure or CDN is secure a rebake should be required to move it back to non-secure. --- lib/url_helper.rb | 2 +- spec/components/cooked_post_processor_spec.rb | 10 +++++++++- spec/components/url_helper_spec.rb | 4 ++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/url_helper.rb b/lib/url_helper.rb index 7db387f1d29..24f6192ac71 100644 --- a/lib/url_helper.rb +++ b/lib/url_helper.rb @@ -18,7 +18,7 @@ class UrlHelper end def self.schemaless(url) - url.sub(/^https?:/, "") + url.sub(/^http:/, "") end end diff --git a/spec/components/cooked_post_processor_spec.rb b/spec/components/cooked_post_processor_spec.rb index b14823ead2d..130686304d4 100644 --- a/spec/components/cooked_post_processor_spec.rb +++ b/spec/components/cooked_post_processor_spec.rb @@ -317,7 +317,7 @@ describe CookedPostProcessor do context "when CDN is enabled" do - it "uses schemaless CDN url for uploads" do + it "does use schemaless CDN url for http uploads" do Rails.configuration.action_controller.stubs(:asset_host).returns("http://my.cdn.com") cpp.optimize_urls expect(cpp.html).to match_html 'Link @@ -325,6 +325,14 @@ describe CookedPostProcessor do ' end + it "does not use schemaless CDN url for https uploads" do + Rails.configuration.action_controller.stubs(:asset_host).returns("https://my.cdn.com") + cpp.optimize_urls + expect(cpp.html).to match_html 'Link + Google + ' + end + end end diff --git a/spec/components/url_helper_spec.rb b/spec/components/url_helper_spec.rb index f0e98b70881..ae2c37d1e7e 100644 --- a/spec/components/url_helper_spec.rb +++ b/spec/components/url_helper_spec.rb @@ -56,9 +56,9 @@ describe UrlHelper do describe "#schemaless" do - it "removes http or https schemas only" do + it "removes http schemas only" do expect(UrlHelper.schemaless("http://www.discourse.org")).to eq("//www.discourse.org") - expect(UrlHelper.schemaless("https://secure.discourse.org")).to eq("//secure.discourse.org") + expect(UrlHelper.schemaless("https://secure.discourse.org")).to eq("https://secure.discourse.org") expect(UrlHelper.schemaless("ftp://ftp.discourse.org")).to eq("ftp://ftp.discourse.org") end