Don't append the base url to absolute image urls without protocol.

This commit is contained in:
Michael Kessler 2013-05-30 17:17:07 +02:00
parent 571e62a27a
commit d2e45cb8fd
3 changed files with 23 additions and 1 deletions

View File

@ -36,7 +36,7 @@ class CookedPostProcessor
images.each do |img| images.each do |img|
src = img['src'] src = img['src']
src = Discourse.base_url_no_prefix + src if src[0] == "/" src = Discourse.base_url_no_prefix + src if src =~ /^\/[^\/]/
if src.present? if src.present?

View File

@ -81,6 +81,23 @@ describe CookedPostProcessor do
end end
end end
context 'with an absolute image path without protocol' do
let(:user) { Fabricate(:user) }
let(:topic) { Fabricate(:topic, user: user) }
let(:post) { Fabricate.build(:post_with_s3_image_url, topic: topic, user: user) }
let(:processor) { CookedPostProcessor.new(post) }
before do
ImageSorcery.any_instance.stubs(:convert).returns(false)
processor.post_process_images
end
it "doesn't change the protocol" do
processor.html.should =~ /src="\/\/bucket\.s3\.amazonaws\.com\/uploads\/6\/4\/123\.png"/
end
end
end end
context 'link convertor' do context 'link convertor' do

View File

@ -34,6 +34,11 @@ Fabricator(:post_with_image_url, from: :post) do
" "
end end
Fabricator(:post_with_s3_image_url, from: :post) do
cooked "
<img src=\"//bucket.s3.amazonaws.com/uploads/6/4/123.png\">
"
end
Fabricator(:basic_reply, from: :post) do Fabricator(:basic_reply, from: :post) do
user(:coding_horror) user(:coding_horror)