FIX: s3 cdn urls not remapped correctly

This commit is contained in:
Sam 2016-06-30 18:58:12 +10:00
parent 342783e716
commit b15f6bd211
2 changed files with 17 additions and 3 deletions

View File

@ -306,7 +306,12 @@ JS
def self.add_s3_cdn(doc) def self.add_s3_cdn(doc)
doc.css("img").each do |img| doc.css("img").each do |img|
next unless img["src"] 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
end end

View File

@ -360,8 +360,17 @@ HTML
SiteSetting.s3_cdn_url = "https://awesome.cdn" SiteSetting.s3_cdn_url = "https://awesome.cdn"
# add extra img tag to ensure it does not blow up # add extra img tag to ensure it does not blow up
raw = "<img><img src='#{Discourse.store.absolute_base_url}/original/9/9/99c9384b8b6d87f8509f8395571bc7512ca3cad1.jpg'" raw = <<HTML
cooked = "<p><img><img src='https://awesome.cdn/original/9/9/99c9384b8b6d87f8509f8395571bc7512ca3cad1.jpg'></p>" <img>
<img src='https:#{Discourse.store.absolute_base_url}/original/9/9/99c9384b8b6d87f8509f8395571bc7512ca3cad1.jpg'>
<img src='http:#{Discourse.store.absolute_base_url}/original/9/9/99c9384b8b6d87f8509f8395571bc7512ca3cad1.jpg'>
<img src='#{Discourse.store.absolute_base_url}/original/9/9/99c9384b8b6d87f8509f8395571bc7512ca3cad1.jpg'>
HTML
cooked = <<HTML
<p> <img><br> <img src="https://awesome.cdn/original/9/9/99c9384b8b6d87f8509f8395571bc7512ca3cad1.jpg"><br> <img src="https://awesome.cdn/original/9/9/99c9384b8b6d87f8509f8395571bc7512ca3cad1.jpg"><br> <img src="https://awesome.cdn/original/9/9/99c9384b8b6d87f8509f8395571bc7512ca3cad1.jpg"></p>
HTML
expect(PrettyText.cook(raw)).to match_html(cooked) expect(PrettyText.cook(raw)).to match_html(cooked)
end end