From 3136638b4b4b39d1ede51045b3349e09c68609e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Tue, 16 Jul 2013 22:16:33 +0200 Subject: [PATCH] FIX: CDN doesn't work with S3 --- lib/pretty_text.rb | 5 +++-- spec/components/cooked_post_processor_spec.rb | 2 +- spec/components/pretty_text_spec.rb | 6 ++++++ 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/pretty_text.rb b/lib/pretty_text.rb index 7c3f74498a0..39e50386616 100644 --- a/lib/pretty_text.rb +++ b/lib/pretty_text.rb @@ -166,17 +166,18 @@ module PrettyText return html unless url image = /\.(jpg|jpeg|gif|png|tiff|tif|bmp)$/ + relative = /^\/[^\/]/ doc = Nokogiri::HTML.fragment(html) doc.css("a").each do |l| href = l["href"].to_s - l["href"] = url + href if href[0] == '/' && href =~ image + l["href"] = url + href if href =~ relative && href =~ image end doc.css("img").each do |l| src = l["src"].to_s - l["src"] = url + src if src[0] == '/' + l["src"] = url + src if src =~ relative end doc.to_s diff --git a/spec/components/cooked_post_processor_spec.rb b/spec/components/cooked_post_processor_spec.rb index 0cc50166c5c..483b78692cc 100644 --- a/spec/components/cooked_post_processor_spec.rb +++ b/spec/components/cooked_post_processor_spec.rb @@ -62,7 +62,7 @@ describe CookedPostProcessor do end - context "with uploaded images" do + context "with locally uploaded images" do let(:upload) { Fabricate(:upload) } let(:post) { Fabricate(:post_with_uploaded_images) } diff --git a/spec/components/pretty_text_spec.rb b/spec/components/pretty_text_spec.rb index a30dcd5a5f9..2235f0cb273 100644 --- a/spec/components/pretty_text_spec.rb +++ b/spec/components/pretty_text_spec.rb @@ -213,9 +213,15 @@ test PrettyText.apply_cdn("hello","http://a.com").should == "hello" end + it "should not touch non images" do PrettyText.apply_cdn("hello","http://a.com").should == "hello" end + + it "should not touch schemaless links" do + PrettyText.apply_cdn("hello","http://a.com").should == + "hello" + end end end