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:
commit
23a57c8d08
|
@ -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
|
||||||
|
|
|
@ -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) }
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue