From b15f6bd211eef7b46438d77159706028406f93b9 Mon Sep 17 00:00:00 2001 From: Sam Date: Thu, 30 Jun 2016 18:58:12 +1000 Subject: [PATCH] FIX: s3 cdn urls not remapped correctly --- lib/pretty_text.rb | 7 ++++++- spec/components/pretty_text_spec.rb | 13 +++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/lib/pretty_text.rb b/lib/pretty_text.rb index 7ac41d2442d..75174a8a826 100644 --- a/lib/pretty_text.rb +++ b/lib/pretty_text.rb @@ -306,7 +306,12 @@ JS def self.add_s3_cdn(doc) doc.css("img").each do |img| next unless img["src"] - img["src"] = img["src"].sub(Discourse.store.absolute_base_url, SiteSetting.s3_cdn_url) + if img["src"].include? Discourse.store.absolute_base_url + src = img["src"].sub(Discourse.store.absolute_base_url, SiteSetting.s3_cdn_url) + # absolute is // style so we may have added an extra https:// here + src = src.sub(/https?:h/, "h") + img["src"] = src + end end end diff --git a/spec/components/pretty_text_spec.rb b/spec/components/pretty_text_spec.rb index 6172faf84c3..0ffd8e85fd9 100644 --- a/spec/components/pretty_text_spec.rb +++ b/spec/components/pretty_text_spec.rb @@ -360,8 +360,17 @@ HTML SiteSetting.s3_cdn_url = "https://awesome.cdn" # add extra img tag to ensure it does not blow up - raw = " + + + + +HTML + + cooked = <


+HTML expect(PrettyText.cook(raw)).to match_html(cooked) end