diff --git a/lib/cooked_post_processor.rb b/lib/cooked_post_processor.rb index 416d8df9e24..8391712900f 100644 --- a/lib/cooked_post_processor.rb +++ b/lib/cooked_post_processor.rb @@ -36,7 +36,7 @@ class CookedPostProcessor images.each do |img| 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? diff --git a/spec/components/cooked_post_processor_spec.rb b/spec/components/cooked_post_processor_spec.rb index 88adf229278..fc1b2d1f3a4 100644 --- a/spec/components/cooked_post_processor_spec.rb +++ b/spec/components/cooked_post_processor_spec.rb @@ -81,6 +81,23 @@ describe CookedPostProcessor do 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 context 'link convertor' do diff --git a/spec/fabricators/post_fabricator.rb b/spec/fabricators/post_fabricator.rb index efa83f59a3f..80919d57889 100644 --- a/spec/fabricators/post_fabricator.rb +++ b/spec/fabricators/post_fabricator.rb @@ -34,6 +34,11 @@ Fabricator(:post_with_image_url, from: :post) do " end +Fabricator(:post_with_s3_image_url, from: :post) do + cooked " + + " +end Fabricator(:basic_reply, from: :post) do user(:coding_horror)