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
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

View File

@ -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) }

View File

@ -213,9 +213,15 @@ test
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\">"
end
it "should not touch non images" do
PrettyText.apply_cdn("<a href='/hello'>hello</a>","http://a.com").should ==
"<a href=\"/hello\">hello</a>"
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