Merge pull request #1208 from ZogStriP/fix-cdn-does-not-work-with-s3

FIX: CDN doesn't work with S3
This commit is contained in:
Robin Ward 2013-07-16 13:27:50 -07:00
commit 23a57c8d08
3 changed files with 10 additions and 3 deletions

View File

@ -166,17 +166,18 @@ module PrettyText
return html unless url return html unless url
image = /\.(jpg|jpeg|gif|png|tiff|tif|bmp)$/ image = /\.(jpg|jpeg|gif|png|tiff|tif|bmp)$/
relative = /^\/[^\/]/
doc = Nokogiri::HTML.fragment(html) doc = Nokogiri::HTML.fragment(html)
doc.css("a").each do |l| doc.css("a").each do |l|
href = l["href"].to_s href = l["href"].to_s
l["href"] = url + href if href[0] == '/' && href =~ image l["href"] = url + href if href =~ relative && href =~ image
end end
doc.css("img").each do |l| doc.css("img").each do |l|
src = l["src"].to_s src = l["src"].to_s
l["src"] = url + src if src[0] == '/' l["src"] = url + src if src =~ relative
end end
doc.to_s doc.to_s

View File

@ -62,7 +62,7 @@ describe CookedPostProcessor do
end end
context "with uploaded images" do context "with locally uploaded images" do
let(:upload) { Fabricate(:upload) } let(:upload) { Fabricate(:upload) }
let(:post) { Fabricate(:post_with_uploaded_images) } let(:post) { Fabricate(:post_with_uploaded_images) }

View File

@ -213,9 +213,15 @@ test
PrettyText.apply_cdn("<a href='/hello.png'>hello</a><img src='/a.jpeg'>","http://a.com").should == PrettyText.apply_cdn("<a href='/hello.png'>hello</a><img src='/a.jpeg'>","http://a.com").should ==
"<a href=\"http://a.com/hello.png\">hello</a><img src=\"http://a.com/a.jpeg\">" "<a href=\"http://a.com/hello.png\">hello</a><img src=\"http://a.com/a.jpeg\">"
end end
it "should not touch non images" do it "should not touch non images" do
PrettyText.apply_cdn("<a href='/hello'>hello</a>","http://a.com").should == PrettyText.apply_cdn("<a href='/hello'>hello</a>","http://a.com").should ==
"<a href=\"/hello\">hello</a>" "<a href=\"/hello\">hello</a>"
end end
it "should not touch schemaless links" do
PrettyText.apply_cdn("<a href='//hello'>hello</a>","http://a.com").should ==
"<a href=\"//hello\">hello</a>"
end
end end
end end